You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by mark goldin <ma...@gmail.com> on 2014/07/12 22:54:54 UTC

Currency value

Is there a reliable way of extracting a value from a currency string?
I am using parse, but it only works well with currencies which have a
currency symbol in the front.

Thanks

Re: Currency value

Posted by jfb <j....@verizon.net>.
Try,
var numericValue = cf.parse( stringValue.replace("$","€") ); 



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Currency-value-tp7244p7255.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Currency value

Posted by mark goldin <ma...@gmail.com>.
The currency symbol and a number of characters it consists of is unknown
for existing field. The user can select any currency and I have to show a
new currency symbol right after.


On Mon, Jul 14, 2014 at 7:26 AM, jfb <j....@verizon.net> wrote:

> This should work:
> var stringValue:String = "$1000"
> var numericValue:Number = parseFloat(stringValue.replace("$",""));
>
> If you like to put the currency back use:
> var cf:CurrencyFormatter = new CurrencyFormatter();
> cf.currencySymbol = '€';
> var stringValue:String = cf.format(numericValue);
>
> I hope this help.
>
>
>
> --
> View this message in context:
> http://apache-flex-users.2333346.n4.nabble.com/Currency-value-tp7244p7256.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Re: Currency value

Posted by jfb <j....@verizon.net>.
This should work:
var stringValue:String = "$1000"
var numericValue:Number = parseFloat(stringValue.replace("$",""));

If you like to put the currency back use:
var cf:CurrencyFormatter = new CurrencyFormatter();
cf.currencySymbol = '€';
var stringValue:String = cf.format(numericValue);

I hope this help.



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Currency-value-tp7244p7256.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Currency value

Posted by mark goldin <ma...@gmail.com>.
What I am doing is a bit different. I need to change a currency type on the
fly. Let's say I have a value shown like this:
$1000. I need to change it to 1000 €. I thought the following code would
work:
 var cf:CurrencyFormatter = new CurrencyFormatter();
var numericValue = cf.parse("$1000");
it does return a numeric value of the currency when a currency symbol in
the front, but parsing Euro that way returns NaN.



On Sun, Jul 13, 2014 at 12:09 PM, Deepak MS <me...@gmail.com>
wrote:

> I tried it with euro and which gets placed at the end of the value. It
> worked fine like earlier example
>
>    var value:int = 893829;
>                 var cf:CurrencyFormatter = new CurrencyFormatter();
>                 cf.currencySymbol = '€';
>                 cf.positiveCurrencyFormat = 3;
>
>                 cf.useCurrencySymbol = true;
>                 var s:String = cf.format(value); // s =  893,829.00 €
>                 var cfr:CurrencyParseResult = cf.parse(s);
> //cfr.currencyString     = "€"  ,     cfr.value     = 893829
>
> or share your code which you trying and we'll see where it is going wrong.
>
>
> On Sun, Jul 13, 2014 at 8:57 PM, mark goldin <ma...@gmail.com>
> wrote:
>
> > Try any currency (Euro) which has a currency symbol at the end of the
> > value.
> >
> >
> > On Sun, Jul 13, 2014 at 9:28 AM, Deepak MS <me...@gmail.com>
> > wrote:
> >
> > > I believe currency string here you meant was using currencyformatter?
> > >
> > >                 var value:int = 893829;
> > >                 var cf:CurrencyFormatter = new CurrencyFormatter();
> > > //import spark.formatters.CurrencyFormatter;
> > >                 cf.currencySymbol = '$';
> > >                 cf.useCurrencySymbol = true;
> > >                 var s:String = cf.format(value); // s =  $893,829.00
> > >                 var cfr:CurrencyParseResult = cf.parse(s);
> > > //cfr.currencyString     = "$"  ,     cfr.value     = 893829
> > >
> > > "but it only works well with currencies which have a
> > > currency symbol in the front."
> > > - I'm not clear on this. Currency formatting would be used with
> currency
> > > symbol. If you dont need currency symbol, you can go for
> NumberFormatter,
> > > which has parseNumber method.
> > >
> > >
> > > On Sun, Jul 13, 2014 at 2:24 AM, mark goldin <ma...@gmail.com>
> > > wrote:
> > >
> > > > Is there a reliable way of extracting a value from a currency string?
> > > > I am using parse, but it only works well with currencies which have a
> > > > currency symbol in the front.
> > > >
> > > > Thanks
> > > >
> > >
> >
>

Re: Currency value

Posted by Deepak MS <me...@gmail.com>.
I tried it with euro and which gets placed at the end of the value. It
worked fine like earlier example

   var value:int = 893829;
                var cf:CurrencyFormatter = new CurrencyFormatter();
                cf.currencySymbol = '€';
                cf.positiveCurrencyFormat = 3;

                cf.useCurrencySymbol = true;
                var s:String = cf.format(value); // s =  893,829.00 €
                var cfr:CurrencyParseResult = cf.parse(s);
//cfr.currencyString     = "€"  ,     cfr.value     = 893829

or share your code which you trying and we'll see where it is going wrong.


On Sun, Jul 13, 2014 at 8:57 PM, mark goldin <ma...@gmail.com> wrote:

> Try any currency (Euro) which has a currency symbol at the end of the
> value.
>
>
> On Sun, Jul 13, 2014 at 9:28 AM, Deepak MS <me...@gmail.com>
> wrote:
>
> > I believe currency string here you meant was using currencyformatter?
> >
> >                 var value:int = 893829;
> >                 var cf:CurrencyFormatter = new CurrencyFormatter();
> > //import spark.formatters.CurrencyFormatter;
> >                 cf.currencySymbol = '$';
> >                 cf.useCurrencySymbol = true;
> >                 var s:String = cf.format(value); // s =  $893,829.00
> >                 var cfr:CurrencyParseResult = cf.parse(s);
> > //cfr.currencyString     = "$"  ,     cfr.value     = 893829
> >
> > "but it only works well with currencies which have a
> > currency symbol in the front."
> > - I'm not clear on this. Currency formatting would be used with currency
> > symbol. If you dont need currency symbol, you can go for NumberFormatter,
> > which has parseNumber method.
> >
> >
> > On Sun, Jul 13, 2014 at 2:24 AM, mark goldin <ma...@gmail.com>
> > wrote:
> >
> > > Is there a reliable way of extracting a value from a currency string?
> > > I am using parse, but it only works well with currencies which have a
> > > currency symbol in the front.
> > >
> > > Thanks
> > >
> >
>

Re: Currency value

Posted by mark goldin <ma...@gmail.com>.
Try any currency (Euro) which has a currency symbol at the end of the value.


On Sun, Jul 13, 2014 at 9:28 AM, Deepak MS <me...@gmail.com> wrote:

> I believe currency string here you meant was using currencyformatter?
>
>                 var value:int = 893829;
>                 var cf:CurrencyFormatter = new CurrencyFormatter();
> //import spark.formatters.CurrencyFormatter;
>                 cf.currencySymbol = '$';
>                 cf.useCurrencySymbol = true;
>                 var s:String = cf.format(value); // s =  $893,829.00
>                 var cfr:CurrencyParseResult = cf.parse(s);
> //cfr.currencyString     = "$"  ,     cfr.value     = 893829
>
> "but it only works well with currencies which have a
> currency symbol in the front."
> - I'm not clear on this. Currency formatting would be used with currency
> symbol. If you dont need currency symbol, you can go for NumberFormatter,
> which has parseNumber method.
>
>
> On Sun, Jul 13, 2014 at 2:24 AM, mark goldin <ma...@gmail.com>
> wrote:
>
> > Is there a reliable way of extracting a value from a currency string?
> > I am using parse, but it only works well with currencies which have a
> > currency symbol in the front.
> >
> > Thanks
> >
>

Re: Currency value

Posted by Deepak MS <me...@gmail.com>.
I believe currency string here you meant was using currencyformatter?

                var value:int = 893829;
                var cf:CurrencyFormatter = new CurrencyFormatter();
//import spark.formatters.CurrencyFormatter;
                cf.currencySymbol = '$';
                cf.useCurrencySymbol = true;
                var s:String = cf.format(value); // s =  $893,829.00
                var cfr:CurrencyParseResult = cf.parse(s);
//cfr.currencyString     = "$"  ,     cfr.value     = 893829

"but it only works well with currencies which have a
currency symbol in the front."
- I'm not clear on this. Currency formatting would be used with currency
symbol. If you dont need currency symbol, you can go for NumberFormatter,
which has parseNumber method.


On Sun, Jul 13, 2014 at 2:24 AM, mark goldin <ma...@gmail.com> wrote:

> Is there a reliable way of extracting a value from a currency string?
> I am using parse, but it only works well with currencies which have a
> currency symbol in the front.
>
> Thanks
>