Ext version tested:Browser versions tested against:
DOCTYPE tested against:Description:
- 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:Possible fix:
Additional CSS used:Operating System:
- 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.