Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting numbers through ExtJS or javascript

I am using string.Format() to format some numbers at the server side.

double dd = 15453434.5345;
            Console.Write(String.Format("{0:N0}", dd));
            Console.Read();

Above code generates:

15,453,435

The number is rounded off and we can see comma separator. How can I achieve this using ExtJS.

like image 811
SharpCoder Avatar asked Mar 23 '23 17:03

SharpCoder


1 Answers

Take a look at Ext.util.Format.

This class is a centralized place for formatting functions. It includes functions to format various different types of data, such as text, dates and numeric values.

Options include:

  • thousandSeparator
  • decimalSeparator
  • currenyPrecision
  • currencySign
  • currencyAtEnd

Example:

Ext.util.Format.thousandSeparator = ',';
Ext.util.Format.decimalSeparator = ',';
var num = (15453434.5345).toFixed(0);

//And then:
Ext.util.Format.number(num, '0,000.00'); //outputs 15,453,435
like image 165
Davor Zubak Avatar answered Apr 10 '23 07:04

Davor Zubak