The following rounding modes are used with ICU's Decimal Formatter. Note that ICU's use of the terms "Down" and "Up" here are somewhat at odds with other definitions, but are equivalent to the same modes used in Java's JDK. Comparison of Rounding ModesThis chart shows the values -2.0 through 2.0 in increments of 0.1, and shows the resulting ICU format when formatted with no decimal digits. #CEILINGFLOORDOWNUPHALFEVENHALFDOWNHALFUP# #CEILINGFLOORDOWNUPHALFEVENHALFDOWNHALFUP# Half EvenThis is ICU's default rounding mode. Values exactly on the 0.5 (half) mark (shown dotted in the chart) are rounded to the nearest even digit. This is often called Banker's Rounding because it is, on average, free of bias. It is the default mode specified for IEEE 754 floating point operations.Also known as ties-to-even, round-to-nearest, RN or RNE. Half DownValues exactly on the 0.5 (half) mark are rounded down (next smaller absolute value, towards zero).Half UpValues exactly on the 0.5 (half) mark are rounded up (next larger absolute value, away from zero).DownAll values are rounded towards the next smaller absolute value (rounded towards zero, or RZ).Also known as: truncation, because the insignificant decimal places are simply removed. UpAll values are rounded towards the next greater absolute value (away from zero).CeilingAll values are rounded towards positive infinity (+∞). Also known as RI for Rounds to Infinity.FloorAll values are rounded towards negative infinity (-∞). Also known as RMI for Rounds to Minus Infinity.UnnecessaryThe mode "Unnecessary" doesn't perform any rounding, but instead returns an error if the value cannot be represented exactly without rounding.Other References/Comparison
|