如何从json获取浮点值?

Raj*_*hal 2 double android json web-services

我正在从jsondata中检索价值

HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000);
HttpResponse response;
HttpGet gett = new HttpGet(URL);

response = client.execute(get);
BufferedReader reader = new BufferedReader(new putStreamReader(response.getEntity().getContent(), "UTF-8"));
orignalResponse = reader.readLine();

JSONTokener tokener = new JSONTokener(orignalResponse);
JSONObject jsonData = new JSONObject(tokener);
Log.v("AMOUNT", "amount :"+jsonData.get("Amount"));
Run Code Online (Sandbox Code Playgroud)

我想要检索"金额",最初是"23868352383.00",
但我正在使用它来检索它

jsonData.get("Amount"),它的值为"2.3868352383E10",

使用jsonData.getDouble("Amount"),它的值为"2.3868352383E10"

使用jsonData.getLong("Amount")它去除分数部分

我怎样才能找到价值?请帮忙.

hat*_*ata 13

BigDecimal类有一个方法floatValue.所以,如果你想比String更漂浮,你也可以使用它.

BigDecimal.valueOf(jsonObject.getDouble("KEY_STRING")).floatValue();
Run Code Online (Sandbox Code Playgroud)


She*_*ady 5

BigDecimal.valueOf(jsonData.getDouble("Amount")).toPlainString()
Run Code Online (Sandbox Code Playgroud)