AFAIK, you cannot do this with JSONObject .
Since there is no such exact floating point value as 52.92 , you really need to use string formatting rules, but then you cannot process the JSON encoder with this value as a number, and not as a quoted string.
You will need:
String json = String.format("{\"price\", %.2f }", f);
In any case, when the JSON is read on the client, it will still not be 52.92 , it will be 52.91999816894531 again. Thus, all that you achieve is a small saving in the amount of your JSON.
Another alternative would be to multiply the number by 100, and then send it as an integer. You will still get 52.91999... if you split it on the client side though!
You can also use a subclass of JSONObject and override this method:
static public java.lang.String numberToString(java.lang.Number number)
source share