• Global community
• Language:
• Deutsch
• English
• Español
• Français
• Português
• 日本語コミュニティ
Dedicated community for Japanese speakers
• 한국 커뮤니티
Dedicated community for Korean speakers
Exit
• Convert a String to Number
Locked

Convert a String to Number

New Here ,
Oct 22, 2010 Oct 22, 2010

Copied

Hi all,

I’m new with Flex 4, and learning

How to convert a formatted string to a number

example “\$54,500.95″ to “54500.95″ in order to do same calculation

any help will be appreciated.

Views

3.0K

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
2 Replies 2
Explorer ,
Oct 22, 2010 Oct 22, 2010

Copied

This might be the solution in case of currency formatter (you can write a utility class and use it)

<code>

<?xml version="1.0" encoding="utf-8"?>

<fx:Script>
<![CDATA[
protected function test_clickHandler(event:MouseEvent):void
{
var value1:String = currency.format(a);
var value2:String = currency.format(b);
var num1:String = value1.substr(1,value1.length);
for(var i:int=0; i<num1.length; i++)
num1 = num1.replace(",","");
var num2:String = value2.substr(1,value2.length);
for(var j:int=0; j<num2.length; j++)
num2 = num2.replace(",","");

var total:Number = Number(num1) + Number(num2);
formatNumber.text =  String(total);

}
]]>
</fx:Script>

<fx:Declarations>
<fx:String id="a">5400000000000.56</fx:String>
<fx:String id="b">550000000000.66</fx:String>
<mx:CurrencyFormatter id="currency" precision="2"/>
</fx:Declarations>

<s:layout>
<s:VerticalLayout/>
</s:layout>

<s:Label text="{currency.format(a)}"/>
<s:Label text="{currency.format(b)}"/>

<s:Label id="formatNumber"/>
<s:Button id="test" label="Convert" click="test_clickHandler(event)"/>

</s:Application>

</code>

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Oct 22, 2010 Oct 22, 2010

Copied

LATEST

Thank you paleti.suresh it works beautiful