My problem is that I make a request in Android application which should return BigDecimal, instead, I got 2.0E7 value. I tried make this request in Postman and it returns 20000000 (proper value). I changed type of value in my data class to BigDecimal and to String and in both cases I got 2.0E7. I need to get the proper value. Can someone help in solving this issue?
Asked
Active
Viewed 305 times
0
-
are you using gson converter ? – Manohar Feb 27 '20 at 06:58
-
Yes I am using gson converter – Asset Bekbossynov Feb 27 '20 at 07:27
-
Gson has this problem see https://github.com/google/gson/issues/968 . There are some work arounds like [this](https://stackoverflow.com/questions/11119094/switch-off-scientific-notation-in-gson-double-serialization) . Use jackson or moshi converters instead of gson – Manohar Feb 27 '20 at 09:18
2 Answers
0
You can use Long type for that (20000000).
In my project I am getting below json and I used long type in my model class
JSON
{
"success": {
"value": 20000000
}
}
Models class
public class Success {
@SerializedName("value")
@Expose
private Long value;
public Long getValue() {
return value;
}
public void setValue(Long value) {
this.value = value;
}
}

Divakar Murugesh
- 1,207
- 1
- 10
- 14
-1
Check this same question How to prevent Gson from converting a long number (a json string ) to scientific notation format?
This May help you...

Rajendra Dabhi
- 157
- 9
-
-
I have the same problem previously and its been resolved by just changing its type to string type. – Rajendra Dabhi Feb 27 '20 at 08:44