views:

63

answers:

1

Here is my code :


NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(14);
nf.setMinimumFractionDigits(0);
double d = 0;
System.out.println(nf.format(d));

With Android SDK : it prints "0.00000000000001" With Java SDK (j2SE) : it prints "0"

Why this difference ? bug in NumberFormat class for Android SDK ?

A: 

I is probably because, as a general rule, double precision numbers are not exact...you cannot have little 0's and 1's create the exact number you are looking for, so, with the java SDK, it probably has algorithms to determine if its inside an Epsilon value, while the android OS doesn't. So yes, it probably is a bug in the NumberFormatter on android OS.

Richard J. Ross III