Monday, April 06, 2009

Today I discovered the "parseNumberString()" function.

I have a textInput that is a formatted currency value. I needed to convert it to a number for calculations. I could have used a regular expression to remove the currency formatting characters. But then I found the "parseNumberString()" function.

Flex help says the parseNumberString() extracts a number from a formatted String. It examines the string from left to right and returns the first number sequence. It ignores thousands separators and includes the decimal and numbers trailing the decimal.

Here's a sample of how to use the function

import mx.formatters.NumberBase;
...
...

public function foo():void
{

var nb:NumberBase = new NumberBase();
var numValue:Number = Number( nb.parseNumberString(strCurrencyValue) );
}