Announcement

Collapse
No announcement yet.

Grid - Format number in custom formatting

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Grid - Format number in custom formatting

    Hi,

    I have the following custom formatting in a grid:

    var markup = '<div style="white-space:normal;">{0} {1}</div>',
    price = v,
    currency = rec.get('CURRENCY');

    return Ext.String.format(markup,price,currency);


    and I would like to format the price to show 2 decimals always.


    Whats the best way to do this?

  • #2
    Hi Theo,

    I would suggest using toFixed which returns a string representing the number with the number of decimal positions supplied.

    Example:
    Code:
    var charNumeric = '100.0112',
        numeric = 100.0112,
        num;
    
    // character number to two decimal places
    //
    num = parseFloat(charNumeric).toFixed(2);
    
    //numeric to two decimal places
    //
    num = numeric.toFixed(2);

    Comment

    Working...
    X