13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Internationalizing applications<br />

var nf:NumberFormatter = new NumberFormatter( "<strong>en</strong>-US" );<br />

var inputNumberString:String = "The value is 123,456,7.890";<br />

var parseResult:NumberParseResult = nf.parse(inputNumberString);<br />

trace("Value:" + parseResult.value); // 1234567.89<br />

trace("startIndex: " + parseResult.startIndex); // 14<br />

trace("Status:" + nf.lastOperationStatus); // noError<br />

The parse() method returns a NumberParseResult object that contains the parsed numeric value in its value property.<br />

The startIndex property indicates the index of the first numeric character that was found. You can use the startIndex<br />

and <strong>en</strong>dIndex properties to extract the portions of the string that come before and after the digits.<br />

Formatting curr<strong>en</strong>cy values<br />

Flash Player 10.1 and later, Adobe AIR 2.0 and later<br />

The display formats of curr<strong>en</strong>cy values vary as much as number formats do. For example, here is how the US dollar<br />

value $123456.78 is formatted for certain locales:<br />

Locale Number Format<br />

<strong>en</strong>-US (English, USA) $123,456.78<br />

de-DE (German, Germany) 123.456,78 $<br />

<strong>en</strong>-IN (English, India) $ 1,23,456.78<br />

Curr<strong>en</strong>cy formatting involves all the same factors as number formatting, plus these additional factors:<br />

Curr<strong>en</strong>cy ISO code. The three letter ISO 4217 curr<strong>en</strong>cy code for the actual locale being used, such as USD or EUR.<br />

Curr<strong>en</strong>cy symbol. The curr<strong>en</strong>cy symbol or string for the actual locale being used, such as $ or €.<br />

Negative curr<strong>en</strong>cy format. Defines the location of the curr<strong>en</strong>cy symbol and the negative symbol or par<strong>en</strong>theses in<br />

relation to the numeric portion of the curr<strong>en</strong>cy amount.<br />

Positive curr<strong>en</strong>cy format. Defines the location of curr<strong>en</strong>cy symbol relative to the numeric portion of the curr<strong>en</strong>cy<br />

amount.<br />

Using the Curr<strong>en</strong>cyFormatter class<br />

The Curr<strong>en</strong>cyFormatter class formats numeric values into strings that contain curr<strong>en</strong>cy strings and formatted<br />

numbers, according to the conv<strong>en</strong>tions of a specific locale.<br />

Wh<strong>en</strong> you instantiate a new Curr<strong>en</strong>cyFormatter object, it sets its curr<strong>en</strong>cy to the default curr<strong>en</strong>cy for the giv<strong>en</strong> locale.<br />

The following example shows that a Curr<strong>en</strong>cyFormatter object created using a German locale assumes that curr<strong>en</strong>cy<br />

amounts are in Euros:<br />

var cf:Curr<strong>en</strong>cyFormatter = new Curr<strong>en</strong>cyFormatter( "de-DE" );<br />

trace(cf.format(1234567.89)); // 1.234.567,89 EUR<br />

In most cases, do not rely on the default curr<strong>en</strong>cy for a locale. If the user’s default locale is not supported, th<strong>en</strong> the<br />

Curr<strong>en</strong>cyFormatter class assigns a fallback locale. The fallback locale can have a differ<strong>en</strong>t default curr<strong>en</strong>cy. In addition,<br />

you normally want the curr<strong>en</strong>cy formats to look correct to your user, ev<strong>en</strong> if the amounts are not in the user’s local<br />

curr<strong>en</strong>cy. For example, a Canadian user can want to see a German company’s prices in Euros, but formatted in the<br />

Canadian style.<br />

Last updated 6/6/2012<br />

945

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!