I want to send my Double
value in json with 2 decimal points. I am using DecimalFormat
class like DecimalFormt.format(value)
, but it gives value in String
. I want the same in Double
type. Is there any way for it as value in json
should be in Double
only not as String
?
Asked
Active
Viewed 107 times
0

Enea Dume
- 3,014
- 3
- 21
- 36

Lalit Thakare
- 23
- 1
- 6
-
Have you tried @Precision(precision = 2)? https://stackoverflow.com/questions/44110624/need-jackson-serializer-for-double-and-need-to-specify-precision-at-runtime – Beri Aug 01 '18 at 12:32
-
If you are not using jackson, try using BigDecimal, set the rounding mode, and then either send the BigDecimal back out through the json and let it convert, or get the double out of the big decimal. – Paul Zepernick Aug 01 '18 at 12:34
-
How are you converting the Java value to JSON? Are you using Jackson or Gson? – Karol Dowbecki Aug 01 '18 at 12:37
-
@Ashu yes, it worked. Thanks. – Lalit Thakare Aug 01 '18 at 13:02