【问题标题】:Flex Spark CurrencyFormatter formats '0' incorrectlyFlex Spark CurrencyFormatter 错误地格式化“0”
【发布时间】:2012-03-02 15:49:00
【问题描述】:

我遇到了火花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 时,它的格式正确。

什么是正确设置才能正确格式化?

【问题讨论】:

    标签: apache-flex flex-spark


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      这是一个例子:

      <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)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-10-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多