Looks like we can't reproduce the issue or there's a problem in the test case provided.
Ext.util.Format.usMoney behaves inappropriately
Ext version tested:
Browser versions tested against:
DOCTYPE tested against:
- Chrome 30.0.1573.2 canary
Steps to reproduce the problem:
- usMoney method passes off to Ext.util.Format.currency which passes off to Ext.util.Format.number. The number method performs rounding based on the format accepted as its second argument. The problem is that it deals with floating point math and this is sometimes not accurate enough.
The result that was expected:
- In chrome console, try Ext.util.Format.number(20.775, "0.00")
- Now try Ext.util.Format.number(20.776, "0.00")
The result that occurs instead:
- In both cases stated above the expected result is "20.78", whether the round method is ROUND_HALF_UP or ROUND_HALF_EVEN it should go to "20.78"
Ext.util.Format.number(20.775, "0.00"); // returns "20.77" expected "20.78"
Ext.util.Format.number(20.776, "0.00"); // returns "20.78" which is expected
Screenshot or Video:
Additional CSS used:
- My personal fix involved pulling in a JS library known as Big.js and use a custom renderer where I need it (numberfields in my grids) to set the value of 20.775 to $20.78 in my grid. Sencha could do something similar in building something like Big.js internally and making the usMoney method pass to this arbitrary decimal precision library. I don't feel like it's appropriate to leave currency formatting up to floating point math.
Last edited by caleywoods; 24 Jul 2013 at 12:31 PM.
Reason: version info added
Thanks for the report! I have opened a bug in our bug tracker.