简体   繁体   English

Flex数字格式

[英]Flex Number Format

I want to format a number in indian format. 我想用印度格式格式化数字。

for example, 例如,

x= 123456 should be formatted as 1,23,456. x = 123456应格式化为1,23,456。

How can i do it in flex? 我怎么能在flex中做到这一点?

Thanks, 谢谢,

Use the numberformatter. 使用数字格式。

<mx:NumberFormatter id="myFormatter"
    decimalSeparatorFrom="."
    decimalSeparatorTo="."
    precision="-1"
    rounding="none"
    thousandsSeparatorFrom=","
    thousandsSeparatorTo=","
    useNegativeSign="true"
    useThousandsSeparator="true"/>

actionscript code 动作代码

x = myFormatter.format(x);

I guess one need to build his/her own number formatter to do this task. 我想有人需要建立他/她自己的数字格式化器来完成这项任务。 Simply using the NumberFormatter will only result into following 简单地使用NumberFormatter只会产生以下结果

123,456 and not 1,23,456 (i.e. the Indian style number formatting)

from http://livedocs.adobe.com/flex/2/langref/mx/formatters/NumberFormatter.html 来自http://livedocs.adobe.com/flex/2/langref/mx/formatters/NumberFormatter.html

Package mx.formatters Class public class NumberFormatter Inheritance NumberFormatter Inheritance Formatter Inheritance Object 包mx.formatters类公共类NumberFormatter继承NumberFormatter继承Formatter继承对象

The NumberFormatter class formats a valid number by adjusting the decimal rounding and precision, the thousands separator, and the negative sign. NumberFormatter类通过调整小数舍入和精度,千位分隔符和负号来格式化有效数字。

If you use both the rounding and precision properties, rounding is applied first, and then you set the decimal length by using the specified precision value. 如果同时使用舍入和精度属性,则首先应用舍入,然后使用指定的精度值设置小数长度。 This lets you round a number and still have a trailing decimal; 这可以让你对一个数字进行舍入,但仍然有一个尾随的小数; for example, 303.99 = 304.00. 例如,303.99 = 304.00。

If an error occurs, an empty String is returned and a String describing the error is saved to the error property. 如果发生错误,则返回空字符串,并将描述错误的String保存到error属性。 The error property can have one of the following values: error属性可以具有以下值之一:

  • "Invalid value" means an invalid numeric value is passed to the format() method. “无效值”表示将无效数值传递给format()方法。 The value should be a valid number in the form of a Number or a String. 该值应为Number或String形式的有效数字。
  • "Invalid format" means one of the parameters contain an unusable setting. “格式无效”表示其中一个参数包含不可用的设置。

MXML Syntaxcollapsed Show MXML Syntax expanded Hide MXML Syntax MXML Syntaxcollapsed Show MXML语法expand隐藏MXML语法

The tag inherits all of the tag attributes of its superclass, and adds the following tag attributes: 标记继承其超类的所有标记属性,并添加以下标记属性:

  <mx:NumberFormatter
    decimalSeparatorFrom="."
    decimalSeparatorTo="."
    precision="-1"
    rounding="none|up|down|nearest"
    thousandsSeparatorFrom=","
    thousandsSeparatorTo=","
    useNegativeSign="true|false"
    useThousandsSeparator="true|false"/>  

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

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