|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.spiffyui.client.NumberFormatter
public final class NumberFormatter
This is a set of utility methods for formatting numbers in a locale-sensitive way. The logic to match formatting with locale was initially taken from jquery-numberformatter 1.2.1, which maps a country to a format. There are 4 different formatting types depending on whether the locale is like US, DE, FR or CH. Locales like US (English) use comma (,) as the number separator and period (.) as the decimal separator. Locales like DE (German) use period (.) as the number separator and comma (,) as the decimal separator. Locales like FR (French) use space ( ) as the number separator and comma (,) as the decimal separator. Locales like CH (Switzerland) use apostrophe (') as the number separator and period (.) as the decimal separator. This utility requires JSDateUtil to determine the locale. For some locales there is no country, in which case we use the language. If none are found it defaults to be like US format. The following countries and languages are supported:
Countries: Arab Emirates -> "AE" Australia -> "AU" Austria -> "AT" Brazil -> "BR" Canada -> "CA" China -> "CN" Czech -> "CZ" Denmark -> "DK" Egypt -> "EG" Finland -> "FI" France -> "FR" Germany -> "DE" Greece -> "GR" Great Britain -> "GB" Hong Kong -> "HK" India -> "IN" Israel -> "IL" Japan -> "JP" Russia -> "RS" South Korea -> "KR" Spain -> "ES" Sweden -> "SE" Switzerland -> "CH" Taiwan -> "TW" Thailand -> "TH" United States -> "US" Vietnam -> "VN" Languages: Chinese -> "zh" Danish -> "da" Dutch -> "nl" English -> "en" French -> "fr" German -> "de" Italian -> "it" Japanese -> "ja" Portuguese -> "pt" Russian -> "ru" Spanish -> "es" Slovak -> "sk" Swedish -> "sv"
Field Summary | |
---|---|
static int |
LIKE_CH
A constant representing locales that are like CH (Switzerland) |
static int |
LIKE_DE
A constant representing locales that are like DE (German) |
static int |
LIKE_FR
A constant representing locales that are like FR (French) |
static int |
LIKE_US
A constant representing locales that are like US (English) |
Method Summary | |
---|---|
static java.lang.String |
format(double number,
java.lang.String pattern)
Return the number formatted to the browser's locale. |
static java.lang.String |
format(int wholeNumber)
Format an integer based on the browser's locale. |
static java.lang.String |
formatWithAbbreviation(double number)
Format the absolute value of the number appending an abbreviation, if necessary. |
protected static java.lang.String |
getGigaString(java.lang.String number)
Returns the number with the localized abbreviation for giga. |
protected static java.lang.String |
getKiloString(java.lang.String number)
Returns the number with the localized abbreviation for kilo. |
static int |
getLikeLocale()
Get the constant representing the 'locale' which the browser locale is similiar to in terms of number formatting |
protected static java.lang.String |
getMegaString(java.lang.String number)
Returns the number with the localized abbreviation for mega. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int LIKE_US
public static final int LIKE_DE
public static final int LIKE_FR
public static final int LIKE_CH
Method Detail |
---|
public static java.lang.String formatWithAbbreviation(double number)
number
- as a double
protected static java.lang.String getKiloString(java.lang.String number)
number
- - a number formatted as a string to be inserted into the parameterized localized string
protected static java.lang.String getMegaString(java.lang.String number)
number
- - a number formatted as a string to be inserted into the parameterized localized string
protected static java.lang.String getGigaString(java.lang.String number)
number
- - a number formatted as a string to be inserted into the parameterized localized string
public static java.lang.String format(double number, java.lang.String pattern)
number
- - the number to format as a Stringpattern
- - a String pattern using the following syntax:
public static int getLikeLocale()
public static java.lang.String format(int wholeNumber)
wholeNumber
- an integer to be formatted
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |