Flex Spark 货币格式化程序格式 '0'不正确地

发布于 2025-01-04 09:34:31 字数 950 浏览 1 评论 0原文

我在使用 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 时,它的格式正确。

使其正确格式化的正确设置是什么?

I'm having trouble with a spark CurrencyFormatter, which is failing to format the value 0 correctly.

All other values are formatted fine.

I'm using Flex 4.5

Here's an example:

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

When the value of the textInput is anything other than 0, it's formatted correctly.

What's the correct setting to get this to format correctly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神魇的王 2025-01-11 09:34:31

I noticed this also. I downloaded example2 from Adobe's help and after tweaking it a bit, I found that if I passed it 0.001, I got "$0.00" in return. This has got to be a bug, otherwise it's just silly. Also, the mx form of the currencyformatter doesn't seem to have this problem. For the meantime, I'm going to be looking for "0" and adding ".001" to the value in my program. Hopefully someone comes up with a better answer.

失眠症患者 2025-01-11 09:34:31

我知道这是一个旧线程,但我会回答未来的疑问。
您可以通过将值 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)

I know this is an old thread, but I am gonna answer for future doubts.
You can solve this problem by setting the value UP to the property rounding of the mx:CurrencyFormatter.

Here is an example:

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

Then in your code, when you format a value 0.001 or 0.00000001, you get "0,01" as a result.

currencyFormatter.format(item.total)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文