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 />

Formatting numbers<br />

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

The display format of numeric values varies widely from region to region. For example, here is how the number<br />

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 />

fr-FR (France, Fr<strong>en</strong>ch) -123 456,78<br />

de-CH (German, Switzerland) -123'456.78<br />

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

Many Arabic locales 123,456.78-<br />

There are many factors that influ<strong>en</strong>ce number formats, including:<br />

Separators. The decimal separator is placed betwe<strong>en</strong> the integer and fractional portions of a number. It can be a<br />

period, comma, or another character. The grouping separator or thousands separator can be a period, a comma, a<br />

non-breaking space, or another character.<br />

Grouping patterns. The number of digits betwe<strong>en</strong> each grouping separator to the left of the decimal point can be<br />

two or three or another value.<br />

Negative number indicators. Negative numbers can be shown with a minus sign to the left or the right of the<br />

number, or within par<strong>en</strong>theses for financial applications. For example, negative 19 can be shown as -19, 19-, or (19).<br />

Leading and trailing zeroes. Some cultural conv<strong>en</strong>tions add leading or trailing zeroes to displayed numbers. For<br />

example the value 0.17 can be displayed as .17, 0.17, or 0.170, among other options.<br />

Sets of digit characters. Many languages, including Hindi, Arabic, and Japanese, use differ<strong>en</strong>t sets of digit<br />

characters. The flash.globalization package supports any digit character sets that map to the digits 0-9.<br />

The NumberFormatter class considers all of these factors wh<strong>en</strong> formatting numeric values.<br />

Using the NumberFormatter class<br />

The NumberFormatter class formats numeric values (of type int, uint, or Number) according to the conv<strong>en</strong>tions of a<br />

specific locale.<br />

The following example shows the simplest way to format a number using the default formatting properties provided<br />

by the user’s operating system:<br />

var nf:NumberFormatter = new NumberFormatter(LocaleID.DEFAULT);<br />

trace(nf.formatNumber(-123456.789))<br />

The result vary based on the user’s locale settings and user prefer<strong>en</strong>ces. For example, if the user’s locale is fr-FR th<strong>en</strong><br />

the formatted value would be:<br />

-123.456,789<br />

If you only want to format a number for a specific locale, regardless of the user’s settings, set the locale name<br />

specifically. For example:<br />

Last updated 6/6/2012<br />

943

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

Saved successfully!

Ooh no, something went wrong!