Question

I'm using stored numeric values in calculations and matching situations and javascript doubles are a big "NO-NO" when doing these kind of operations.

However I can't find a solution on how to use java BigDecimal in SSJS in Xpages.

Since one should construct a BigDecimal using a string I have tried different approaches i SSJS. Whatever test the result is the same, the call is ambiguous:

Ambiguity when calling new java.math.BigDecimal(long) and new java.math.BigDecimal(int)

  1. How do I use a BigDecimal in my SSJS when values are stored in documents as Numbers?
  2. How do I use BigDecimal with a string argument when values are stored in documents as Numbers?

edit/amend: After accepting Svens answer I got a bit further and to my second question.

The value retrieved from the document is 451368 but it will be stored in variable as 451367.99999999994

How do I recover from that when the user should match against original value?

Was it helpful?

Solution

Use Java-Objects instead:

var value = new java.lang.Integer(1);
new java.math.BigDecimal(value);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top