Search code examples
extjsextjs4.1sencha-architectextjs4.2

How to round off a float value in extjs4.1


Can anybody tell me how to round a float value in extjs4.1? For example, if I have the value 24.536, I need to round it to 24.54. If I have 24.534, I need to round it to 24.53.


Solution

  • If you realy want round number, use it:

    number = Math.round(number * 100) / 100;
    

    Extend

    If you want show rounded number - you may use ExtJs numbe format tools. Try this:

    //Set these once, right after Ext.onReady
    Ext.util.Format.thousandSeparator = ' ';
    Ext.util.Format.decimalSeparator = '.';
    
    //Then this should round your number correctly:
    Ext.util.Format.number(12345.00, '0,000.00'); //output 12 345.67