How to Implement Rounding Up to Nearest Hundred Value Using Round System Function

Purpose of Document

How can I implement rounding to round a number up to the nearest hundred value?  When attempting to use the rounding function, a definition of round (99,950.00, -2) returns 10,000.00 not 100,000.00.

Is this working as designed? How do I define this to round to the nearest hundred value?

It is working as designed.  The index or second number has to be greater than or equal to zero.  The system function round(number,number) is defined as "Round to a specified number of decimal places" although it does not specify that the index (which is the second number) must be greater than or equal to 0. 

This round system function, available in Expression Manager, is making use of math.round() from 'math' C library.

For example, by defining round(12.4567, n) the system will use the following calculation:

  1. Multiply it using pow(10, n)
  2. Round it
  3. Divide it by the value of n.


If n = 2, then:

  1. Multiply it using pow(10, 2) = 12.4567 * 100 = 1245.67
  2. Round it = round(1245.67) = 1246
  3. Divide it by the value multiplied from 1 = 1245/100 = 12.46


Since the index (2nd number from round(number,number)) cannot be a negative integer, the following example can be implemented to round to the nearest hundred value.

  1. Divide input value by 100 = 99,950.00/100
  2. Round it using the round function = round(999.50, 0) = 1,000
  3. Multiply it with the value used from step 1 = 1,000 * 100 = 100,000


The same implementation can be found from the business function B0000605 - MathNumericRoundScientific.

 

ParametersAliasDirImplementation
mnNumberOfDecimals (15 [2]) MATH01 IN The value which is greater than or equal to <zero>
mnUnroundedMathNumericValue (15 [2]) MATH01 IN Value to round
mnRoundedMathNumericValue (15 [2]) MATH01 OUT Rounded value
szRoundedStringValue (30) DL40 OUT Return value in String
cErrorCode (1) ERRC OUT Hard Error 2 if input mnNumberOfDecimals is negative value

 

NOTE: The JDE API mathround() will round up where the number of decimal is defined in Data Dictionary item