I have a response from the web service and this response is a json type string. I get the STHAR_GCMIK value here using obj.getString().
This code works correctly up to 6 digit values, but it returns 4.0E+7 for the value 4000000. I tried different solutions but failed. How can I display the value here as it is?
private AttrsSiparis parseSiparisBilgisi(String data) {
AttrsSiparis siparisBilgileri = new AttrsSiparis();
try {
JSONArray jsonArray = new JSONArray(data);
for(int i = 0; i < jsonArray.length(); i++)
{
JSONObject obj = jsonArray.getJSONObject(i);
Log.i(Constants.TAG, "Irsaliye Result Parse : STHAR_GCMIK " + obj.getString("STHAR_GCMIK"));
//siparisBilgileri.miktarlar.add(obj.getString("STHAR_GCMIK"));
siparisBilgileri.miktarlar.add(new BigDecimal(obj.getString("STHAR_GCMIK")).toString());
}
} catch (JSONException e) {
e.printStackTrace();
return null;
}
return siparisBilgileri;
}
3
Answers
I solved this error by first converting the incoming data to double type and then formatting it as string type.
I guess you are talking about displaying the already parsed
BigDecimal
. If so, then if you are logging or printing it, it uses itstoString()
method. This method uses the scientific notation by default.If you want to display the number as it is You have to use the
toPlainString()
method – it doesn’t use the scientific notation.You can format it to
double
via.getDouble("STHAR_GCMTK")
and then convert that toString
.