The code is as below:
float f = 1.7f;
JSONArray ja = new JSONArray();
try {
ja.put(f);
Log.d("json", "f=" + f);
Log.d("json", "ja=" + ja.toString());
} catch (JSONException e) {
e.printStackTrace();
}
The output is:
05-16 17:49:30.559 32554-32554/com.group.home D/json﹕ f=1.7
05-16 17:49:30.559 32554-32554/com.group.home D/json﹕ ja=[1.7000000476837158]
If f
is 1.0
, then the output will be ja=1
.
Where does the 000000476837158
come from? How should I prevent this from happening?