Topic: DMD0546

Help File Version: 2.10.0.636

MROUND - Adjust to Given Multiple


The Round to Given Multiple (MROUND) function rounds the input number up, away from zero, if the remainder of dividing the number by multiple is greater than or equal to half the value of the given multiple; else it rounds down toward zero. The function requires two parameters: the first is the number to round, the second is the multiple to which you want to round.

 

This function always returns a Real value, so result should be placed in a Real memory location.

 

Both parameters must be positive, or both be negative. If the signs don't match, the result will be 0 and a Pos / Neg Mismatch math error will be generated. If the second parameter is 0 the result will be 0 and the Divide by Zero math error will be set.

 

Both parameters are expressions, which can be a numeric constant values, numeric memory locations, arithmetic expression or mathematical functions, or additional expressions up to a maximum of 1024 characters. Expressions can be nested, so use of parentheses is recommended to ensure proper evaluation order. Traditional math precedence rules are used to solve the math expression, so the use of parentheses to remove any ambiguity in the processing order is encouraged.

 

Refer to the examples below:

 

 

R0 = MROUND( 3.72, 2 )

R0 = 4.0

 

Rounds 3.72 up to nearest multiple of 2.

 

 

R0 = MROUND( 1.58, 0.1 )

R0 = 1.6

 

Rounds 1.58 up to the nearest multiple of 0.1.

 

 

R0 = MROUND( 0.234, 0.01 )

R0 = 0.23

 

Rounds 0.234 up to the nearest multiple of 0.01.

 

 

R0 = MROUND( -2.5, -2 )

R0 = -2.0

 

Rounds -2.5 down to nearest multiple of -2.

 

 

R0 = MROUND( -2.5, 2 )

R0 =0.0

 

Signs of the parameters are different, the result will be 0 (Pos / Neg Mismatch math error will be set).

 

 

R0 = MROUND( 3.72, 0 )

R0 = 0.0

 

MROUND of any number to a multiple of 0 is 0 (Divide by Zero math error will be set).

 

 

R0 = MROUND( ( R1 + R2 ) / 2.0, 3 )

 

Assume R1 = 6.0 and R2 = 1.44

R0 = 3.0

 

Adds R1 and R2, then divides that by 2.0, then rounds up to the nearest multiple of 3.

 

 

 


See Also:

CEILING - Adjust Up To Significance

 

FLOOR - Adjust Down To Significance



MROUND - Round to Multiple

 


Related Topics:

MATH - Calculate Expression

 

FRAC - Fractional Portion of a Real Number

 

ROUND - Round Real to Nearest Whole Number

 

TRUNC - Truncate Real to Whole Number