According to the DecimalFormat specification, the rounding is defined as
"Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor."
However, the following program shows that the rounding is done incorrectly.
import java.text.*;
import java.util.*;
public class ParseTest {
public static void main(String[] args) {
DecimalFormat df = new DecimalFormat("#,##0.###", new DecimalFormatSymbols(Locale.ENGLISH));
df.setMultiplier(100);
ParsePosition pp = new ParsePosition(0);
System.out.println(df.parse("9223372036854775806", pp));
}
}
The output is 92233720368547760. However,
9223372036854775806 = 92233720368547758.06 * 100
and 92233720368547758.06 rounds to 92233720368547758, according to the specification.
"Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor."
However, the following program shows that the rounding is done incorrectly.
import java.text.*;
import java.util.*;
public class ParseTest {
public static void main(String[] args) {
DecimalFormat df = new DecimalFormat("#,##0.###", new DecimalFormatSymbols(Locale.ENGLISH));
df.setMultiplier(100);
ParsePosition pp = new ParsePosition(0);
System.out.println(df.parse("9223372036854775806", pp));
}
}
The output is 92233720368547760. However,
9223372036854775806 = 92233720368547758.06 * 100
and 92233720368547758.06 rounds to 92233720368547758, according to the specification.
- duplicates
-
JDK-6177299 [Fmt-Nu] NumberFormat.getPercentInstance() does not work correctly
-
- Resolved
-