質問

I have this currencyFormatter :

<s:CurrencyFormatter id="currencyFormatter" currencySymbol="€"  useGrouping="true"  groupingSeparator="." decimalSeparator="," fractionalDigits="2" useCurrencySymbol="true" locale="de-DE" />

Everything works just fine, but the problem is when I enter a value "24,50" it is not accepted. But if I enter "24.50" it is accepted and converted into "€ 24,50"

I need to be able to enter currency with comma as decimal separator.

could someone please help?

役に立ちましたか?

解決 3

well my solution, no doubt ugly, but works... I am kind of quick and dirty solution sort of a guy I guess :P

Before formatting the entered text (at focusOut event) I simply replace the comma "," with a period ".". So the formatter can do its magic and stay happy (thinking it converted a period into a comma :D )

The second problem was easier, I simply used the built in parse method of formatter and it gives me an attribute 'value' which has the value as a number stored!
Problem Solved!! thank you for your help guys!
cheers!

他のヒント

Had to do this myself, and could'nt override the value in the CurrencyFormatter class... but you can put a SharedResources in your local directory, locale/en_US/SharedResources.properties, and change/add the decimalSeparator variable with a value of comma.

The file resides:

*C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.6\sdks\4.6.0\frameworks\projects\framework\bundles\en_US\SharedResources.properties*

so you can have a look at it, but you will want to include an override of this in your project, and include it in the swf that gets built

You should only be using the formatter for display purposes if you want to retain it's original value. You need to extend spark.formatters.CurrencyFormatter and override the format function to accept commas because the value passed into the function is cast as a Number and then determined to be a NaN.

package

{

import spark.formatters.CurrencyFormatter;

public class MyCurrencyFormatter extends CurrencyFormatter
{
    public function MyCurrencyFormatter()
    {
        super();
    }
    override public function format(value:Object):String{
        var target:Object = value;
        if(target is String){
            //whatever conversion logic you need
            target = String(target).replace(",",".");
        }
        return super.format(target);
    }
}

}

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top