RoundingMode.TowardZero

Updated on

RoundingMode.TowardZero (3) is an enumeration that specifies rounding direction when there is a tie between the possible numbers to round to. It is a member of the RoundingMode.Type and indicates rounding toward zero.

Examples

Below examples round the main value to 3 decimals. The value 9.5555 has four decimals and needs to get rid of one. RoundMode.TowardZero makes sure that the rounding of the 4th decimals happen toward zero.

= Number.Round(  9.5555, 3,  3 )                      // Returns 9.555
= Number.Round(  9.5555, 3, RoundingMode.TowardZero ) // Returns 9.555
= Number.Round( -9.5554, 3, RoundingMode.TowardZero ) // Returns -9.555

When the decimal to round is higher than half, it is also rounded up toward zero.

= Number.Round( 9.6650, 2, RoundingMode.TowardZero ) // Returns 9.66

Note that when Number having fewer decimals than instructed by the rounding, the entire value is returned unrounded.

= Number.Round( 9.55, 3, RoundingMode.TowardZero ) // Returns 9.55

You can find an example for all functions supporting the RoundingMode.Type below.

= Number.Round(  9.5, 0,    RoundingMode.TowardZero ) // Returns 9
= Number.Round( -9.5, 0,    RoundingMode.TowardZero ) // Returns -9

= Byte.From(     9.5, null, RoundingMode.TowardZero ) // Returns 9
= Byte.From(    -9.5, null, RoundingMode.TowardZero ) // Returns -9

= Int8.From(     9.5, null, RoundingMode.TowardZero ) // Returns 9
= Int8.From(    -9.5, null, RoundingMode.TowardZero ) // Returns -9

= Int16.From(    9.5, null, RoundingMode.TowardZero ) // Returns 9
= Int16.From(   -9.5, null, RoundingMode.TowardZero ) // Returns -9

= Int32.From(    9.5, null, RoundingMode.TowardZero ) // Returns 9
= Int32.From(   -9.5, null, RoundingMode.TowardZero ) // Returns -9
 
= Int64.From(    9.5, null, RoundingMode.TowardZero ) // Returns 9
= Int64.From(   -9.5, null, RoundingMode.TowardZero ) // Returns -9


// Currency From Function returns a maximum of 4 decimals
= Currency.From(  9.66005, null, RoundingMode.TowardZero ) // Returns  9.66
= Currency.From( -9.66005, null, RoundingMode.TowardZero ) // Returns -9.66

Other related enumerations are:

Applies to

Here’s a list of functions that work with RoundingMode.Type:

Contribute » | Contributors: Rick de Groot

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy