Strange float output "@.0E-12" on BlackBerry Android player

1.3k Views Asked by At

I have an app that works well on many Android devices, but there is a problem on the BlackBerry Android player running on the PlayBook (it runs Android 2.3).

I had a NumberFormatException on PreferenceManager.getDefaultSharedPreferences(). It appeared that in the preferences file, a float was saved as "@.0E-12". I made this simple test:

float f = 1.0e-12f;
System.out.println (f); // prints "@.0E-12" on BlackBerry PlayBook !!

How can this be?

2

There are 2 best solutions below

1
Royi On

its a very small number (i.e. 0.000000..01).
if it means anything to you you can try BigDecimal.
otherwise you can decide that numbers that are smaller than x (you decide how small the x is) are 0.

3
18446744073709551615 On

If your question is How can this be?, I think you can download the Android source, find relevant sources in libcore/luni/src/main/java/java/lang, and, starting from Float.toString(), begin to import function by function to your project, checking each time that the bug is still seen. You will locate the bug, it is likely something related to FP math. (Maybe, something like random bits in the least significant part of mantissa.)