12e5b6d6dSopenharmony_ci---
22e5b6d6dSopenharmony_cilayout: default
32e5b6d6dSopenharmony_cititle: Rounding Modes
42e5b6d6dSopenharmony_cinav_order: 2
52e5b6d6dSopenharmony_cigrand_parent: Formatting
62e5b6d6dSopenharmony_ciparent: Formatting Numbers
72e5b6d6dSopenharmony_ci---
82e5b6d6dSopenharmony_ci<!--
92e5b6d6dSopenharmony_ci© 2020 and later: Unicode, Inc. and others.
102e5b6d6dSopenharmony_ciLicense & terms of use: http://www.unicode.org/copyright.html
112e5b6d6dSopenharmony_ci-->
122e5b6d6dSopenharmony_ci
132e5b6d6dSopenharmony_ci# Rounding Modes
142e5b6d6dSopenharmony_ci{: .no_toc }
152e5b6d6dSopenharmony_ci
162e5b6d6dSopenharmony_ci## Contents
172e5b6d6dSopenharmony_ci{: .no_toc .text-delta }
182e5b6d6dSopenharmony_ci
192e5b6d6dSopenharmony_ci1. TOC
202e5b6d6dSopenharmony_ci{:toc}
212e5b6d6dSopenharmony_ci
222e5b6d6dSopenharmony_ci---
232e5b6d6dSopenharmony_ci
242e5b6d6dSopenharmony_ciThe following rounding modes are used with ICU's Decimal Formatter. Note that
252e5b6d6dSopenharmony_ciICU's use of the terms "Down" and "Up" here are somewhat at odds with other
262e5b6d6dSopenharmony_cidefinitions, but are equivalent to the same modes used in Java's JDK.
272e5b6d6dSopenharmony_ci
282e5b6d6dSopenharmony_ci## Comparison of Rounding Modes
292e5b6d6dSopenharmony_ci
302e5b6d6dSopenharmony_ciThis chart shows the values -2.0 through 2.0 in increments of 0.1, and shows the
312e5b6d6dSopenharmony_ciresulting ICU format when formatted with no decimal digits.
322e5b6d6dSopenharmony_ci
332e5b6d6dSopenharmony_ci*Note: Some of the options below are not available in ICU4J because we use the JDK RoundingMode.*
342e5b6d6dSopenharmony_ci
352e5b6d6dSopenharmony_ci| #    | CEILING | FLOOR | DOWN | UP | HALFEVEN | HALFODD | HALFCEILING | HALFFLOOR | HALFDOWN | HALFUP | #    |
362e5b6d6dSopenharmony_ci|------|---------|-------|------|----|----------|---------|-------------|-----------|----------|--------|------|
372e5b6d6dSopenharmony_ci| -2.0 | -2      | -2    | -2   | -2 | -2       | -2      | -2          | -2        | -2       | -2     | -2.0 |
382e5b6d6dSopenharmony_ci| -1.9 | -1      | -2    | -1   | -2 | -2       | -2      | -2          | -2        | -2       | -2     | -1.9 |
392e5b6d6dSopenharmony_ci| -1.8 | -1      | -2    | -1   | -2 | -2       | -2      | -2          | -2        | -2       | -2     | -1.8 |
402e5b6d6dSopenharmony_ci| -1.7 | -1      | -2    | -1   | -2 | -2       | -2      | -2          | -2        | -2       | -2     | -1.7 |
412e5b6d6dSopenharmony_ci| -1.6 | -1      | -2    | -1   | -2 | -2       | -2      | -2          | -2        | -2       | -2     | -1.6 |
422e5b6d6dSopenharmony_ci| -1.5 | -1      | -2    | -1   | -2 | -2       | -1      | -1          | -2        | -1       | -2     | -1.5 |
432e5b6d6dSopenharmony_ci| -1.4 | -1      | -2    | -1   | -2 | -1       | -1      | -1          | -1        | -1       | -1     | -1.4 |
442e5b6d6dSopenharmony_ci| -1.3 | -1      | -2    | -1   | -2 | -1       | -1      | -1          | -1        | -1       | -1     | -1.3 |
452e5b6d6dSopenharmony_ci| -1.2 | -1      | -2    | -1   | -2 | -1       | -1      | -1          | -1        | -1       | -1     | -1.2 |
462e5b6d6dSopenharmony_ci| -1.1 | -1      | -2    | -1   | -2 | -1       | -1      | -1          | -1        | -1       | -1     | -1.1 |
472e5b6d6dSopenharmony_ci| -1.0 | -1      | -1    | -1   | -1 | -1       | -1      | -1          | -1        | -1       | -1     | -1.0 |
482e5b6d6dSopenharmony_ci| -0.9 | -0      | -1    | -0   | -1 | -1       | -1      | -1          | -1        | -1       | -1     | -0.9 |
492e5b6d6dSopenharmony_ci| -0.8 | -0      | -1    | -0   | -1 | -1       | -1      | -1          | -1        | -1       | -1     | -0.8 |
502e5b6d6dSopenharmony_ci| -0.7 | -0      | -1    | -0   | -1 | -1       | -1      | -1          | -1        | -1       | -1     | -0.7 |
512e5b6d6dSopenharmony_ci| -0.6 | -0      | -1    | -0   | -1 | -1       | -1      | -1          | -1        | -1       | -1     | -0.6 |
522e5b6d6dSopenharmony_ci| -0.5 | -0      | -1    | -0   | -1 | -0       | -1      | -0          | -1        | -0       | -1     | -0.5 |
532e5b6d6dSopenharmony_ci| -0.4 | -0      | -1    | -0   | -1 | -0       | -0      | -0          | -0        | -0       | -0     | -0.4 |
542e5b6d6dSopenharmony_ci| -0.3 | -0      | -1    | -0   | -1 | -0       | -0      | -0          | -0        | -0       | -0     | -0.3 |
552e5b6d6dSopenharmony_ci| -0.2 | -0      | -1    | -0   | -1 | -0       | -0      | -0          | -0        | -0       | -0     | -0.2 |
562e5b6d6dSopenharmony_ci| -0.1 | -0      | -1    | -0   | -1 | -0       | -0      | -0          | -0        | -0       | -0     | -0.1 |
572e5b6d6dSopenharmony_ci| 0.0  | 0       | 0     | 0    | 0  | 0        | 0       | 0           | 0         | 0        | 0      | 0.0  |
582e5b6d6dSopenharmony_ci| 0.1  | 1       | 0     | 0    | 1  | 0        | 0       | 0           | 0         | 0        | 0      | 0.1  |
592e5b6d6dSopenharmony_ci| 0.2  | 1       | 0     | 0    | 1  | 0        | 0       | 0           | 0         | 0        | 0      | 0.2  |
602e5b6d6dSopenharmony_ci| 0.3  | 1       | 0     | 0    | 1  | 0        | 0       | 0           | 0         | 0        | 0      | 0.3  |
612e5b6d6dSopenharmony_ci| 0.4  | 1       | 0     | 0    | 1  | 0        | 0       | 0           | 0         | 0        | 0      | 0.4  |
622e5b6d6dSopenharmony_ci| 0.5  | 1       | 0     | 0    | 1  | 0        | 1       | 1           | 0         | 0        | 1      | 0.5  |
632e5b6d6dSopenharmony_ci| 0.6  | 1       | 0     | 0    | 1  | 1        | 1       | 1           | 1         | 1        | 1      | 0.6  |
642e5b6d6dSopenharmony_ci| 0.7  | 1       | 0     | 0    | 1  | 1        | 1       | 1           | 1         | 1        | 1      | 0.7  |
652e5b6d6dSopenharmony_ci| 0.8  | 1       | 0     | 0    | 1  | 1        | 1       | 1           | 1         | 1        | 1      | 0.8  |
662e5b6d6dSopenharmony_ci| 0.9  | 1       | 0     | 0    | 1  | 1        | 1       | 1           | 1         | 1        | 1      | 0.9  |
672e5b6d6dSopenharmony_ci| 1.0  | 1       | 1     | 1    | 1  | 1        | 1       | 1           | 1         | 1        | 1      | 1.0  |
682e5b6d6dSopenharmony_ci| 1.1  | 2       | 1     | 1    | 2  | 1        | 1       | 1           | 1         | 1        | 1      | 1.1  |
692e5b6d6dSopenharmony_ci| 1.2  | 2       | 1     | 1    | 2  | 1        | 1       | 1           | 1         | 1        | 1      | 1.2  |
702e5b6d6dSopenharmony_ci| 1.3  | 2       | 1     | 1    | 2  | 1        | 1       | 1           | 1         | 1        | 1      | 1.3  |
712e5b6d6dSopenharmony_ci| 1.4  | 2       | 1     | 1    | 2  | 1        | 1       | 1           | 1         | 1        | 1      | 1.4  |
722e5b6d6dSopenharmony_ci| 1.5  | 2       | 1     | 1    | 2  | 2        | 1       | 2           | 1         | 1        | 2      | 1.5  |
732e5b6d6dSopenharmony_ci| 1.6  | 2       | 1     | 1    | 2  | 2        | 2       | 2           | 2         | 2        | 2      | 1.6  |
742e5b6d6dSopenharmony_ci| 1.7  | 2       | 1     | 1    | 2  | 2        | 2       | 2           | 2         | 2        | 2      | 1.7  |
752e5b6d6dSopenharmony_ci| 1.8  | 2       | 1     | 1    | 2  | 2        | 2       | 2           | 2         | 2        | 2      | 1.8  |
762e5b6d6dSopenharmony_ci| 1.9  | 2       | 1     | 1    | 2  | 2        | 2       | 2           | 2         | 2        | 2      | 1.9  |
772e5b6d6dSopenharmony_ci| 2.0  | 2       | 2     | 2    | 2  | 2        | 2       | 2           | 2         | 2        | 2      | 2.0  |
782e5b6d6dSopenharmony_ci| #    | CEILING | FLOOR | DOWN | UP | HALFEVEN | HALFODD | HALFCEILING | HALFFLOOR | HALFDOWN | HALFUP | #    |
792e5b6d6dSopenharmony_ci
802e5b6d6dSopenharmony_ci### Half Even
812e5b6d6dSopenharmony_ci
822e5b6d6dSopenharmony_ciThis is ICU's default rounding mode. Values exactly on the 0.5 (half) mark
832e5b6d6dSopenharmony_ci(shown dotted in the chart) are rounded to the nearest even digit. This is often
842e5b6d6dSopenharmony_cicalled Banker's Rounding because it is, on average, free of bias. It is the
852e5b6d6dSopenharmony_cidefault mode specified for IEEE 754 floating point operations.
862e5b6d6dSopenharmony_ci
872e5b6d6dSopenharmony_ciAlso known as ties-to-even, round-to-nearest, RN or RNE.
882e5b6d6dSopenharmony_ci
892e5b6d6dSopenharmony_ci### Half Odd
902e5b6d6dSopenharmony_ci
912e5b6d6dSopenharmony_ciSimilar to Half Even, but rounds ties to the nearest odd number instead of even number.
922e5b6d6dSopenharmony_ci
932e5b6d6dSopenharmony_ci### Half Down
942e5b6d6dSopenharmony_ci
952e5b6d6dSopenharmony_ciValues exactly on the 0.5 (half) mark are rounded down (next smaller absolute
962e5b6d6dSopenharmony_civalue, towards zero).
972e5b6d6dSopenharmony_ci
982e5b6d6dSopenharmony_ci### Half Up
992e5b6d6dSopenharmony_ci
1002e5b6d6dSopenharmony_ciValues exactly on the 0.5 (half) mark are rounded up (next larger absolute
1012e5b6d6dSopenharmony_civalue, away from zero).
1022e5b6d6dSopenharmony_ci
1032e5b6d6dSopenharmony_ci### Down
1042e5b6d6dSopenharmony_ci
1052e5b6d6dSopenharmony_ciAll values are rounded towards the next smaller absolute value (rounded towards
1062e5b6d6dSopenharmony_cizero, or RZ).
1072e5b6d6dSopenharmony_ci
1082e5b6d6dSopenharmony_ciAlso known as: truncation, because the insignificant decimal places are simply
1092e5b6d6dSopenharmony_ciremoved.
1102e5b6d6dSopenharmony_ci
1112e5b6d6dSopenharmony_ci### Up
1122e5b6d6dSopenharmony_ci
1132e5b6d6dSopenharmony_ciAll values are rounded towards the next greater absolute value (away from zero).
1142e5b6d6dSopenharmony_ci
1152e5b6d6dSopenharmony_ci### Half Ceiling
1162e5b6d6dSopenharmony_ci
1172e5b6d6dSopenharmony_ciValues exactly on the 0.5 (half) mark are rounded toward positive infinity (+∞).
1182e5b6d6dSopenharmony_ci
1192e5b6d6dSopenharmony_ciThis is the default rounding mode in ECMAScript. In CSS, it is known as "nearest".
1202e5b6d6dSopenharmony_ci
1212e5b6d6dSopenharmony_ci### Half Floor
1222e5b6d6dSopenharmony_ci
1232e5b6d6dSopenharmony_ciValues exactly on the 0.5 (half) mark are rounded towards negative infinity (-∞).
1242e5b6d6dSopenharmony_ci
1252e5b6d6dSopenharmony_ci### Ceiling
1262e5b6d6dSopenharmony_ci
1272e5b6d6dSopenharmony_ciAll values are rounded towards positive infinity (+∞). Also known as RI for
1282e5b6d6dSopenharmony_ciRounds to Infinity.
1292e5b6d6dSopenharmony_ci
1302e5b6d6dSopenharmony_ci### Floor
1312e5b6d6dSopenharmony_ci
1322e5b6d6dSopenharmony_ciAll values are rounded towards negative infinity (-∞). Also known as RMI for
1332e5b6d6dSopenharmony_ciRounds to Minus Infinity.
1342e5b6d6dSopenharmony_ci
1352e5b6d6dSopenharmony_ci### Unnecessary
1362e5b6d6dSopenharmony_ci
1372e5b6d6dSopenharmony_ciThe mode "Unnecessary" doesn't perform any rounding, but instead returns an
1382e5b6d6dSopenharmony_cierror if the value cannot be represented exactly without rounding.
1392e5b6d6dSopenharmony_ci
1402e5b6d6dSopenharmony_ci## **Other References/Comparison**
1412e5b6d6dSopenharmony_ci
1422e5b6d6dSopenharmony_ci*   Decimal Context docs (used by ICU4C to implement rounding):
1432e5b6d6dSopenharmony_ci    <http://speleotrove.com/decimal/decifaq1.html#rounding>
1442e5b6d6dSopenharmony_ci*   Java 7 docs:
1452e5b6d6dSopenharmony_ci    <http://docs.oracle.com/javase/7/docs/api/java/math/RoundingMode.html>
1462e5b6d6dSopenharmony_ci*   IEEE 754 rounding rules:
1472e5b6d6dSopenharmony_ci    <http://en.wikipedia.org/wiki/IEEE_754-2008#Rounding_rules>
1482e5b6d6dSopenharmony_ci*   Wikipedia article on Rounding:
1492e5b6d6dSopenharmony_ci    <http://en.wikipedia.org/wiki/Rounding#Tie-breaking>
1502e5b6d6dSopenharmony_ci*   Live rounding mode chart: [Rounding Mode
1512e5b6d6dSopenharmony_ci    Chart](https://htmlpreview.github.io/?https://github.com/unicode-org/icu-demos/blob/main/roundmode/round.html)
1522e5b6d6dSopenharmony_ci    and [Source
1532e5b6d6dSopenharmony_ci    Code](https://github.com/unicode-org/icu-demos/tree/main/roundmode)
154