SYNTAX

<Decimal>.round

<Decimal>.round(<Integer>)

<Decimal>.round(<Integer>, roundingMode: <Integer>)

  • When <Integer> is not provided, <Decimal> is rounded to the nearest whole number of type Decimal.
  • When <Integer> is provided , <Decimal> is rounded to the number of decimal places specified by <Integer>. Standard rounding conventions apply, meaning numbers ending with significant digits of 5 or more round up and numbers ending with significant digits less than 5 round down.
  • When <Integer> and roundingMode: <Integer> are provided , then <Decimal> is rounded to the number of decimal places specified by the mode:
    • 0 - Rounds away from zero
    • 1 - Rounds towards zero
    • 2 - Rounds towards Infinity
    • 3 - Rounds towards -Infinity
    • 4 - Rounds towards nearest neighbor; if equidistant, rounds away from zero
    • 5 - Rounds towards nearest neighbor; if equidistant, rounds towards zero
    • 6 - Rounds towards nearest neighbor; if equidistant, rounds towards even neighbor
    • 7 - Rounds towards nearest neighbor; if equidistant, rounds towards Infinity
    • 8 - Rounds towards nearest neighbor; if equidistant, rounds towards -Infinity

The Operators row of the table in Summary Table of Vocabulary Usage Restriction applies. No special exceptions.

The following Rulesheet uses .round to round the value of decimal2 to the second decimal place, and assigns it to decimal1.

A sample Ruletest provides results for five examples of decimal2.

0 (ROUND UP) Rounds away from zero

	10.123 -> 10.13

1 (ROUND DOWN) Rounds towards zero

	10.123 -> 10.12

2 (ROUND CEIL) 2 Rounds towards Infinity

	10.123 -> 10.13

3 (ROUND_FLOOR) Rounds towards -Infinity

	10.123 -> 10.12

4 (ROUND_HALF_UP) Rounds towards nearest neighbor. If equidistant, rounds away from zero

	10.123 -> 10.12
	10.126 -> 10.13
	10.125 -> 10.13

5 (ROUND_HALF_DOWN) Rounds towards nearest neighbor. If equidistant, rounds towards zero

	10.123 -> 10.12
	10.126 -> 10.13
	10.125 -> 10.12

6 (ROUND_HALF_EVEN ) Rounds towards nearest neighbor. If equidistant, rounds towards even neighbor

See Round to Even (Banker's Rounding) https://www.mathsisfun.com/numbers/rounding-methods.html and https://en.wikipedia.org/wiki/Rounding

	8.123 -> 8.12
	9.126 -> 9.13
	// variation from other modes: go to nearest even number
	10.125 -> 10.12
	11.135 -> 11.14

7 (ROUND_HALF_CEIL) Rounds towards nearest neighbor. If equidistant, rounds towards Infinity

	9.123 -> 9.12
	10.126 -> 10.1
	11.125 -> 11.13

8 (ROUND_HALF_FLOOR) Rounds towards nearest neighbor. If equidistant, rounds towards -Infinity

	9.123 -> 9.12
	10.126 -> 10.13
	11.125 -> 11.12