• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1---
2layout: default
3title: Rounding Modes
4nav_order: 2
5grand_parent: Formatting
6parent: Formatting Numbers
7---
8<!--
9© 2020 and later: Unicode, Inc. and others.
10License & terms of use: http://www.unicode.org/copyright.html
11-->
12
13# Rounding Modes
14{: .no_toc }
15
16## Contents
17{: .no_toc .text-delta }
18
191. TOC
20{:toc}
21
22---
23
24The following rounding modes are used with ICU's Decimal Formatter. Note that
25ICU's use of the terms "Down" and "Up" here are somewhat at odds with other
26definitions, but are equivalent to the same modes used in Java's JDK.
27
28## Comparison of Rounding Modes
29
30This chart shows the values -2.0 through 2.0 in increments of 0.1, and shows the
31resulting ICU format when formatted with no decimal digits.
32
33*Note: Some of the options below are not available in ICU4J because we use the JDK RoundingMode.*
34
35| #    | CEILING | FLOOR | DOWN | UP | HALFEVEN | HALFODD | HALFCEILING | HALFFLOOR | HALFDOWN | HALFUP | #    |
36|------|---------|-------|------|----|----------|---------|-------------|-----------|----------|--------|------|
37| -2.0 | -2      | -2    | -2   | -2 | -2       | -2      | -2          | -2        | -2       | -2     | -2.0 |
38| -1.9 | -1      | -2    | -1   | -2 | -2       | -2      | -2          | -2        | -2       | -2     | -1.9 |
39| -1.8 | -1      | -2    | -1   | -2 | -2       | -2      | -2          | -2        | -2       | -2     | -1.8 |
40| -1.7 | -1      | -2    | -1   | -2 | -2       | -2      | -2          | -2        | -2       | -2     | -1.7 |
41| -1.6 | -1      | -2    | -1   | -2 | -2       | -2      | -2          | -2        | -2       | -2     | -1.6 |
42| -1.5 | -1      | -2    | -1   | -2 | -2       | -1      | -1          | -2        | -1       | -2     | -1.5 |
43| -1.4 | -1      | -2    | -1   | -2 | -1       | -1      | -1          | -1        | -1       | -1     | -1.4 |
44| -1.3 | -1      | -2    | -1   | -2 | -1       | -1      | -1          | -1        | -1       | -1     | -1.3 |
45| -1.2 | -1      | -2    | -1   | -2 | -1       | -1      | -1          | -1        | -1       | -1     | -1.2 |
46| -1.1 | -1      | -2    | -1   | -2 | -1       | -1      | -1          | -1        | -1       | -1     | -1.1 |
47| -1.0 | -1      | -1    | -1   | -1 | -1       | -1      | -1          | -1        | -1       | -1     | -1.0 |
48| -0.9 | -0      | -1    | -0   | -1 | -1       | -1      | -1          | -1        | -1       | -1     | -0.9 |
49| -0.8 | -0      | -1    | -0   | -1 | -1       | -1      | -1          | -1        | -1       | -1     | -0.8 |
50| -0.7 | -0      | -1    | -0   | -1 | -1       | -1      | -1          | -1        | -1       | -1     | -0.7 |
51| -0.6 | -0      | -1    | -0   | -1 | -1       | -1      | -1          | -1        | -1       | -1     | -0.6 |
52| -0.5 | -0      | -1    | -0   | -1 | -0       | -1      | -0          | -1        | -0       | -1     | -0.5 |
53| -0.4 | -0      | -1    | -0   | -1 | -0       | -0      | -0          | -0        | -0       | -0     | -0.4 |
54| -0.3 | -0      | -1    | -0   | -1 | -0       | -0      | -0          | -0        | -0       | -0     | -0.3 |
55| -0.2 | -0      | -1    | -0   | -1 | -0       | -0      | -0          | -0        | -0       | -0     | -0.2 |
56| -0.1 | -0      | -1    | -0   | -1 | -0       | -0      | -0          | -0        | -0       | -0     | -0.1 |
57| 0.0  | 0       | 0     | 0    | 0  | 0        | 0       | 0           | 0         | 0        | 0      | 0.0  |
58| 0.1  | 1       | 0     | 0    | 1  | 0        | 0       | 0           | 0         | 0        | 0      | 0.1  |
59| 0.2  | 1       | 0     | 0    | 1  | 0        | 0       | 0           | 0         | 0        | 0      | 0.2  |
60| 0.3  | 1       | 0     | 0    | 1  | 0        | 0       | 0           | 0         | 0        | 0      | 0.3  |
61| 0.4  | 1       | 0     | 0    | 1  | 0        | 0       | 0           | 0         | 0        | 0      | 0.4  |
62| 0.5  | 1       | 0     | 0    | 1  | 0        | 1       | 1           | 0         | 0        | 1      | 0.5  |
63| 0.6  | 1       | 0     | 0    | 1  | 1        | 1       | 1           | 1         | 1        | 1      | 0.6  |
64| 0.7  | 1       | 0     | 0    | 1  | 1        | 1       | 1           | 1         | 1        | 1      | 0.7  |
65| 0.8  | 1       | 0     | 0    | 1  | 1        | 1       | 1           | 1         | 1        | 1      | 0.8  |
66| 0.9  | 1       | 0     | 0    | 1  | 1        | 1       | 1           | 1         | 1        | 1      | 0.9  |
67| 1.0  | 1       | 1     | 1    | 1  | 1        | 1       | 1           | 1         | 1        | 1      | 1.0  |
68| 1.1  | 2       | 1     | 1    | 2  | 1        | 1       | 1           | 1         | 1        | 1      | 1.1  |
69| 1.2  | 2       | 1     | 1    | 2  | 1        | 1       | 1           | 1         | 1        | 1      | 1.2  |
70| 1.3  | 2       | 1     | 1    | 2  | 1        | 1       | 1           | 1         | 1        | 1      | 1.3  |
71| 1.4  | 2       | 1     | 1    | 2  | 1        | 1       | 1           | 1         | 1        | 1      | 1.4  |
72| 1.5  | 2       | 1     | 1    | 2  | 2        | 1       | 2           | 1         | 1        | 2      | 1.5  |
73| 1.6  | 2       | 1     | 1    | 2  | 2        | 2       | 2           | 2         | 2        | 2      | 1.6  |
74| 1.7  | 2       | 1     | 1    | 2  | 2        | 2       | 2           | 2         | 2        | 2      | 1.7  |
75| 1.8  | 2       | 1     | 1    | 2  | 2        | 2       | 2           | 2         | 2        | 2      | 1.8  |
76| 1.9  | 2       | 1     | 1    | 2  | 2        | 2       | 2           | 2         | 2        | 2      | 1.9  |
77| 2.0  | 2       | 2     | 2    | 2  | 2        | 2       | 2           | 2         | 2        | 2      | 2.0  |
78| #    | CEILING | FLOOR | DOWN | UP | HALFEVEN | HALFODD | HALFCEILING | HALFFLOOR | HALFDOWN | HALFUP | #    |
79
80### Half Even
81
82This is ICU's default rounding mode. Values exactly on the 0.5 (half) mark
83(shown dotted in the chart) are rounded to the nearest even digit. This is often
84called Banker's Rounding because it is, on average, free of bias. It is the
85default mode specified for IEEE 754 floating point operations.
86
87Also known as ties-to-even, round-to-nearest, RN or RNE.
88
89### Half Odd
90
91Similar to Half Even, but rounds ties to the nearest odd number instead of even number.
92
93### Half Down
94
95Values exactly on the 0.5 (half) mark are rounded down (next smaller absolute
96value, towards zero).
97
98### Half Up
99
100Values exactly on the 0.5 (half) mark are rounded up (next larger absolute
101value, away from zero).
102
103### Down
104
105All values are rounded towards the next smaller absolute value (rounded towards
106zero, or RZ).
107
108Also known as: truncation, because the insignificant decimal places are simply
109removed.
110
111### Up
112
113All values are rounded towards the next greater absolute value (away from zero).
114
115### Half Ceiling
116
117Values exactly on the 0.5 (half) mark are rounded toward positive infinity (+∞).
118
119This is the default rounding mode in ECMAScript. In CSS, it is known as "nearest".
120
121### Half Floor
122
123Values exactly on the 0.5 (half) mark are rounded towards negative infinity (-∞).
124
125### Ceiling
126
127All values are rounded towards positive infinity (+∞). Also known as RI for
128Rounds to Infinity.
129
130### Floor
131
132All values are rounded towards negative infinity (-∞). Also known as RMI for
133Rounds to Minus Infinity.
134
135### Unnecessary
136
137The mode "Unnecessary" doesn't perform any rounding, but instead returns an
138error if the value cannot be represented exactly without rounding.
139
140## **Other References/Comparison**
141
142*   Decimal Context docs (used by ICU4C to implement rounding):
143    <http://speleotrove.com/decimal/decifaq1.html#rounding>
144*   Java 7 docs:
145    <http://docs.oracle.com/javase/7/docs/api/java/math/RoundingMode.html>
146*   IEEE 754 rounding rules:
147    <http://en.wikipedia.org/wiki/IEEE_754-2008#Rounding_rules>
148*   Wikipedia article on Rounding:
149    <http://en.wikipedia.org/wiki/Rounding#Tie-breaking>
150*   Live rounding mode chart: [Rounding Mode
151    Chart](https://htmlpreview.github.io/?https://github.com/unicode-org/icu-demos/blob/main/roundmode/round.html)
152    and [Source
153    Code](https://github.com/unicode-org/icu-demos/tree/main/roundmode)
154