2012-02-10 106 views
2

我遇到了火花CurrencyFormatter,它无法正确格式化值0Flex Spark CurrencyFormatter格式'0'格式错误

所有其他值的格式都很好。

我使用Flex 4.5

下面是一个例子:

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> 
    <fx:Declarations> 
     <s:CurrencyFormatter currencyISOCode="GBP" id="formatter" useCurrencySymbol="true" currencySymbol="£" trailingZeros="true" leadingZero="true" negativeCurrencyFormat="0" positiveCurrencyFormat="0" /> 
    </fx:Declarations> 
    <s:HGroup> 
     <s:TextInput id="textInput" /> 
     <s:Label text="{formatter.format(textInput.text)}" /> 
    </s:HGroup> 
</s:Application> 

textInput的值不为0的,它的格式正确无误。

正确设置此格式的正确设置是什么?

回答

3

我也注意到了这一点。我从Adobe's help下载了example2,在调整了一下后,我发现如果我通过了0.001,我得到了“0.00美元”的回报。这必须是一个错误,否则就是愚蠢的。另外,currencyformatter的mx格式似乎没有这个问题。与此同时,我将要查找“0”并将“.001”添加到我的程序中的值中。希望有人提出一个更好的答案。

0

我知道这是一个古老的线程,但我会回答以备将来的疑惑。 您可以通过将值UP设置为mx:CurrencyFormatter的属性来解决此问题。

下面是一个例子:

<mx:CurrencyFormatter 
     id="currencyFormatter" 
     currencySymbol="" 
     precision="2" 
     rounding="up" 
     decimalSeparatorFrom="," 
     decimalSeparatorTo="," 
     useNegativeSign="true" 
     useThousandsSeparator="true" 
     thousandsSeparatorFrom="." 
     thousandsSeparatorTo="." 
     alignSymbol="left" /> 

然后在你的代码,当你格式化值0.001 0.00000001,你会得到“0.01”作为结果。

currencyFormatter.format(item.total)