Unexpected BigDecimal truncation while using JsonObject.fromJson(jsonString)


While trying to persist a Couchbase record, the attributes of BigDecimal type are automatically rounded off to 15 decimal digits while using JsonObject.fromJson(…). I believe it uses float64 (double) implicitly.

(ObjectMapper is used to form the below JsonString from a POJO containing two BigDecimal types - There is no problem in this conversion.)

Expected Result:

Actual Result:

Please suggest a solution to retain the digits.

N1QL uses float64 (golang native data type for decimal is float64) for JSON number. You can use ROUND() to round the number. If you need precision more than 15 digits, Convert the value to string and back in the application or USE SDK retrieve data directly.

1 Like