简体   繁体   English

通过ExtJS或javascript格式化数字

[英]Formatting numbers through ExtJS or javascript

I am using string.Format() to format some numbers at the server side. 我正在使用string.Format()来格式化服务器端的一些数字。

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

Above code generates: 以上代码生成:

15,453,435 15453435

The number is rounded off and we can see comma separator. 数字四舍五入,我们可以看到逗号分隔符。 How can I achieve this using ExtJS. 如何使用ExtJS实现此目的。

Take a look at Ext.util.Format . 看看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 thousandSeparator
  • decimalSeparator decimalSeparator
  • currenyPrecision currenyPrecision
  • currencySign currencySign
  • currencyAtEnd 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM