Search code examples
javascriptjavagwtbigdecimal

How is BigDecimal represented in the JavaScript compiled by GWT


In GWT one can use java.math.BigDecimal in the client code. How are these BigDecimals represented in the resulting JavaScript code after compilation? Is there some extra class for that or do they use a native JavaScript object?


Solution

  • BigDecimal has no special treatment by the GWT Compiler. It's emulated with a bunch of fields, with a small optimization for the case where the value is in the java.lang.Double (equivalent to a JS Number) value range; but from the point of view of JS code, it's an opaque Object.

    See https://github.com/gwtproject/gwt/blob/2.7.0/user/super/com/google/gwt/emul/java/math/BigDecimal.java#L523-L558