Table of contents
TOC
Collapse the table of content
Expand the table of content

Number.Round

Owen Duncan|Last Updated: 4/19/2018

About

Returns a nullable number (n) if value is an integer.

Number.Round(value as nullable number, digits as nullable number,  roundingMode as nullable number) as nullable number  

Arguments

ArgumentDescription
valueInteger value to round.
digitsFractional part is rounded by digits.
roundingModeSpecifies rounding direction when there is a tie between the possible numbers to round to. For Example, when the last digit of the number being rounded is 5 such as. 1.5 or 2.345.

Settings

Rounding modeDescription
RoundingMode.Up = 0Adds 5e-n to the number being rounded, where n is the number of fractional digits in the number.
RoundingMode.Down = 1Subtracts 5e-n from the number being rounded, where n is the number of fractional digits in the number.
RoundingMode.AwayFromZero = 2The same as RoundingMode.Up when the number being rounded is positive; otherwise, the same as

RoundingMode.Down.
RoundingMode.TowardZero = 3The same as RoundingMode.Down when the number being rounded is positive; otherwise, the same as RoundingMode.Up.
RoundingMode.ToEven = 4Applies RoundingMode.Up or

RoundingMode.Down to round the last digit to even.

Remarks

  • If value >= 0, returns n with the fractional part rounded by digits using roundingMode.

  • if value < 0, it returns the integral part of n rounded to m-n decimal digits, using roundingMode, where m is the number of digits of n.

  • If roundingMode is not specified, RoundingMode.ToEven is used.

Examples

Number.Round(-1.249, 2) equals -1.25  
Number.Round(-1.245, 2) equals -1.24  
Number.Round(1.245, 2, RoundingMode.Up) equals 1.25  
Number.Round(1.245, 2, RoundingMode.Down) equals 1.24  
Number.Round(1.245, 2, RoundingMode.AwayFromZero) equals 1.25  
Number.Round(1.245, 2, RoundingMode.TowardZero) equals 1.24  
Number.Round(1.245, 2, RoundingMode.ToEven) equals 1.24  
Number.Round(-1.245, 2, RoundingMode.ToEven) equals -1.24  
© 2018 Microsoft