I have BigDecimal objects serialized with BlazeDS to Actionscript. Once they hit Actionscript as Number objects, they have values like:
140475.32 turns into 140475.31999999999998
How do I deal with this? The problem is that if I use a NumberFormatter with precision of 2, then the value is truncated to 140475.31. Any ideas?
This is my generic solution for the problem (I have blogged about this here):
For example:
0.12345678by10; that gives us1.2345678.1.2345678, we get1.0,1.0divided by10equals0.1.Another example:
1.7302394309234435by10000; that gives us17302.394309234435.17302.394309234435we get17302,17302divided by10000equals1.7302.Edit
Based on the anonymous answer below, there is a nice simplification for the parameter on the method that makes the precision much more intuitive. e.g:
N.B. I added this here just in case anyone sees this as the answer and doesn’t scroll down…