0

In my project, I use Spring @ResponseBody and When I return a Object contains BigDecimal like that :

{
  "messageType" : "",
  "messageContent" : "",
  "valueObj" : 100.00,
  "redirectUrl" : "",
  "success" : false
}

then, the response body in browser is

{
  "messageType" : "",
  "messageContent" : "",
  "valueObj" : 100,
  "redirectUrl" : "",
  "success" : false
} 

I have a problem with BigDecimal Precision loosing. its precision (100.00 --> 100).

What is the problem with Spring to convert BigDecimal. Would you please provide me the solution?

Bourbia Brahim
  • 14,459
  • 4
  • 39
  • 52

1 Answers1

0

Actually the precision is not lost in your example. 100.00 is the same as 100 as the value is written as a number and not a String. If the value would be serialized as a String "valueObj" : "100" you could argue that it is a difference but not for a number.

You would have a problem if e.g. 100.01 is shorten to 100, but is this also the case?

Simulant
  • 19,190
  • 8
  • 63
  • 98