Marty Pitt
Marty Pitt

Reputation: 29290

Flex Spark CurrencyFormatter formats '0' incorrectly

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?

Upvotes: 2

Views: 871

Answers (2)

henriqueor
henriqueor

Reputation: 939

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)

Upvotes: 0

Sean Lemson
Sean Lemson

Reputation: 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.

Upvotes: 3

Related Questions