Problem handling large numbers (BigDecimal)


#1

I am running the JVM with -Dcom.couchbase.json.decimalForFloat=true

I can insert a large numeric values, I can query it correctly using key access (bucket.get(“KEY1”)).
It is retrieved correctly when I use asterisk in the query.
The number is truncated when I specify the field explicitly in the query.
Please see my test case bellow:

 // Running with -Dcom.couchbase.json.decimalForFloat=true
@Test
public void testDemoTestCase() {
    final JsonDocument docToUpsert = JsonDocument.create(
          "KEY1",
          JsonObject.fromJson("{\"largeNumber\": 654654654654654654654654654654654654654654654654654.68798798798654654654654654654654645}"));
    bucket.upsert(docToUpsert);

    // Printing out correctly "654654654654654654654654654654654654654654654654654.68798798798654654654654654654654645"
    JsonDocument jsonDocument = bucket.get("KEY1");
    System.out.println(jsonDocument.content().getBigDecimal("largeNumber"));

    // Printing out correctly [{"tests":{"largeNumber":654654654654654654654654654654654654654654654654654.68798798798654654654654654654654645}}]
    N1qlQueryResult result = bucket.query(N1qlQuery.simple("select * from tests"));
    System.out.println(result.allRows());

    // Truncated number is printed [{"largeNumber":654654654654654700000000000000000000000000000000000}]
    result = bucket.query(N1qlQuery.simple("select largeNumber from tests"));
    System.out.println(result.allRows());
}

Is there a way how to get not truncated results when using a query?
Any kind of advice is appreciated.
Thanks.


#2

N1QL uses float64 as numeric data type. big numbers will loose precision when assigned to float64


#3

Thanks for clarification. Is there any roadmap to support a numeric data type suitable for monetary calculations? Something like the decimal128 - IEEE 754 decimal128 decimal-based floating-point numbering format?