i18n.NumberFormat Extends
Constructor of NumberFormat.

Inheritance

Constructor

goog.i18n.NumberFormat(patternopt_currencyopt_currencyStyle)

Parameters

pattern : number | string
The number that indicates a predefined number format pattern.
opt_currency : string=
Optional international currency code. This determines the currency code/symbol used in format/parse. If not given, the currency code for current locale will be used.
opt_currencyStyle : number=
currency style, value defined in goog.i18n.NumberFormat.CurrencyStyle.

Instance Methods

Public Protected Private
addExponentPart_(exponentparts)
Formats exponent part of a Number.
Arguments:
exponent : number
Exponential value.
parts : Array.<string>
The array that holds the pieces of formatted string. This function will append more formatted pieces to the array.
code »
applyCompactStyle_(style)
Apply a predefined pattern for shorthand formats.
Arguments:
style : goog.i18n.NumberFormat.CompactStyle
the compact style to set defaults for.
code »
applyPattern_(pattern)
Apply provided pattern, result are stored in member variables.
Arguments:
pattern : string
String pattern being applied.
code »
applyStandardPattern_(patternType)
Apply a predefined pattern to NumberFormat object.
Arguments:
patternType : number
The number that indicates a predefined number format pattern.
code »
format(number) string
Formats a Number to produce a string.
Arguments:
number : number
The Number to be formatted.
Returns: string  The formatted number string.
code »
getBaseFormatting() ?number
Gets the number on which compact formatting is currently based, or null if no such number is set. See setBaseFormatting() for more information.
Returns: ?number  No description.
code »
getDigit_(ch) number
Returns the digit value of current character. The character could be either '0' to '9', or a locale specific digit.
Arguments:
ch : string
Character that represents a digit.
Returns: number  The digit value, or -1 on error.
code »
getSignificantDigits() number
Gets number of significant digits to show. Only fractions will be rounded.
Returns: number  The number of significant digits to include.
code »
getUnitAfterRounding_(formattingNumberpluralityNumber) !goog.i18n.NumberFormat.CompactNumberUnit
Get the compact unit divisor, accounting for rounding of the quantity.
Arguments:
formattingNumber : number
The number to base the formatting on. The unit will be calculated from this number.
pluralityNumber : number
The number to use for calculating the plurality.
Returns: !goog.i18n.NumberFormat.CompactNumberUnit  The unit after rounding.
code »
getUnitFor_(baseplurality) !goog.i18n.NumberFormat.CompactNumberUnit
Get compact unit for a certain number of digits
Arguments:
base : number
The number of digits to get the unit for.
plurality : string
The plurality of the number.
Returns: !goog.i18n.NumberFormat.CompactNumberUnit  The compact unit.
code »
intLog10_(number) number
Get the integer base 10 logarithm of a number.
Arguments:
number : number
The number to log.
Returns: number  The lowest integer n such that 10^n >= number.
code »
isCurrencyCodeBeforeValue() boolean
Checks if the currency symbol comes before the value ($12) or after (12$) Handy for applications that need to have separate UI fields for the currency value and symbol, especially for input: Price: [USD] [123.45] The currency symbol might be a combo box, or a label.
Returns: boolean  true if currency is before value.
code »
parse(textopt_pos) number
Parses text string to produce a Number. This method attempts to parse text starting from position "opt_pos" if it is given. Otherwise the parse will start from the beginning of the text. When opt_pos presents, opt_pos will be updated to the character next to where parsing stops after the call. If an error occurs, opt_pos won't be updated.
Arguments:
text : string
The string to be parsed.
opt_pos : Array.<number>>
Position to pass in and get back.
Returns: number  Parsed number. This throws an error if the text cannot be parsed.
code »
parseAffix_(patternpos) string
Parses affix part of pattern.
Arguments:
pattern : string
Pattern string that need to be parsed.
pos : Array.<number>
One element position array to set and receive parsing position.
Returns: string  Affix received from parsing.
code »
parseNumber_(textpos) number
This function will parse a "localized" text into a Number. It needs to handle locale specific decimal, grouping, exponent and digits.
Arguments:
text : string
The text that need to be parsed.
pos : Array.<number>
In/out parsing position. In case of failure, pos value won't be changed.
Returns: number  Number value, or NaN if nothing can be parsed.
code »
parseTrunk_(patternpos)
Parses the trunk part of a pattern.
Arguments:
pattern : string
Pattern string that need to be parsed.
pos : Array.<number>
One element position array to set and receive parsing position.
code »
pluralForm_(quantity) string
Get the plural form of a number.
Arguments:
quantity : number
The quantity to find plurality of.
Returns: string  One of 'zero', 'one', 'two', 'few', 'many', 'other'.
code »
roundNumber_(number) {intValue: number, fracValue: number
Round a number into an integer and fractional part based on the rounding rules for this NumberFormat.
Arguments:
number : number
The number to round.
Returns: {intValue: number, fracValue: number  } The integer and fractional part after rounding.
code »
roundToSignificantDigits_(numbersignificantDigitsscale) number
Round to a certain number of significant digits.
Arguments:
number : number
The number to round.
significantDigits : number
The number of significant digits to round to.
scale : number
Treat number as fixed point times 10^scale.
Returns: number  The rounded number.
code »
setBaseFormatting(baseFormattingNumber) !goog.i18n.NumberFormat
Sets a number to base the formatting on when compact style formatting is used. If this is null, the formatting should be based only on the number to be formatting. This base formatting number can be used to format the target number as another number would be formatted. For example, 100,000 is normally formatted as "100K" in the COMPACT_SHORT format. To instead format it as '0.1M', the base number could be set to 1,000,000 in order to force all numbers to be formatted in millions. Similarly, 1,000,000,000 would normally be formatted as '1B' and setting the base formatting number to 1,000,000, would cause it to be formatted instead as '1,000M'.
Arguments:
baseFormattingNumber : ?number
The number to base formatting on, or null if formatting should not be based on another number.
Returns: !goog.i18n.NumberFormat  Reference to this NumberFormat object.
code »
setMaximumFractionDigits(max) !goog.i18n.NumberFormat
Sets maximum number of fraction digits.
Arguments:
max : number
the maximum.
Returns: !goog.i18n.NumberFormat  Reference to this NumberFormat object.
code »
setMinimumFractionDigits(min) !goog.i18n.NumberFormat
Sets minimum number of fraction digits.
Arguments:
min : number
the minimum.
Returns: !goog.i18n.NumberFormat  Reference to this NumberFormat object.
code »
setShowTrailingZeros(showTrailingZeros) !goog.i18n.NumberFormat
Sets whether trailing fraction zeros should be shown when significantDigits_ is positive. If this is true and significantDigits_ is 2, 1 will be formatted as '1.0'.
Arguments:
showTrailingZeros : boolean
Whether trailing zeros should be shown.
Returns: !goog.i18n.NumberFormat  Reference to this NumberFormat object.
code »
setSignificantDigits(number) !goog.i18n.NumberFormat
Sets number of significant digits to show. Only fractions will be rounded.
Arguments:
number : number
The number of significant digits to include.
Returns: !goog.i18n.NumberFormat  Reference to this NumberFormat object.
code »
subformatExponential_(numberparts)
Formats Number in exponential format.
Arguments:
number : number
Value need to be formated.
parts : Array.<string>
The array that holds the pieces of formatted string. This function will append more formatted pieces to the array.
code »
subformatFixed_(numberminIntDigitsparts)
Formats a Number in fraction format.
Arguments:
number : number
No description.
minIntDigits : number
Minimum integer digits.
parts : Array
This array holds the pieces of formatted string. This function will add its formatted pieces to the array.
code »

Instance Properties

baseFormattingNumber_ :
The number to base the formatting on when using compact styles, or null if formatting should not be based on another number.
Code »
compactStyle_ :
No description.
Code »
currencyStyle_ :
No description.
Code »
decimalSeparatorAlwaysShown_ :
No description.
Code »
groupingSize_ :
No description.
Code »
intlCurrencyCode_ :
No description.
Code »
maximumFractionDigits_ :
No description.
Code »
maximumIntegerDigits_ :
No description.
Code »
minExponentDigits_ :
No description.
Code »
minimumFractionDigits_ :
No description.
Code »
minimumIntegerDigits_ :
No description.
Code »
multiplier_ :
No description.
Code »
negativePrefix_ :
No description.
Code »
negativeSuffix_ :
No description.
Code »
positivePrefix_ :
No description.
Code »
positiveSuffix_ :
No description.
Code »
showTrailingZeros_ :
Whether to show trailing zeros in the fraction when significantDigits_ is positive.
Code »
significantDigits_ :
No description.
Code »
useExponentialNotation_ :
No description.
Code »
useSignForPositiveExponent_ :
No description.
Code »

Static Methods

goog.i18n.NumberFormat.isEnforceAsciiDigits() boolean
Return if Ascii digits is enforced.
Returns: boolean  If Ascii digits is enforced.
code »
goog.i18n.NumberFormat.setEnforceAsciiDigits(doEnforce)
Set if the usage of Ascii digits in formatting should be enforced.
Arguments:
doEnforce : boolean
Boolean value about if Ascii digits should be enforced.
code »

Static Properties

goog.i18n.NumberFormat.CompactNumberUnit :
Alias for the compact format 'unit' object.
Code »
goog.i18n.NumberFormat.NULL_UNIT_ :
The empty unit, corresponding to a base of 0.
Code »
goog.i18n.NumberFormat.PATTERN_CURRENCY_SIGN_ :
A quote character.
Code »
goog.i18n.NumberFormat.PATTERN_DECIMAL_SEPARATOR_ :
A decimal separator character.
Code »
goog.i18n.NumberFormat.PATTERN_DIGIT_ :
A digit character.
Code »
goog.i18n.NumberFormat.PATTERN_EXPONENT_ :
An exponent character.
Code »
goog.i18n.NumberFormat.PATTERN_GROUPING_SEPARATOR_ :
A grouping separator character.
Code »
goog.i18n.NumberFormat.PATTERN_MINUS_ :
A minus character.
Code »
goog.i18n.NumberFormat.PATTERN_PERCENT_ :
A percent character.
Code »
goog.i18n.NumberFormat.PATTERN_PER_MILLE_ :
A per mille character.
Code »
goog.i18n.NumberFormat.PATTERN_PLUS_ :
An plus character.
Code »
goog.i18n.NumberFormat.PATTERN_SEPARATOR_ :
A separator character.
Code »
goog.i18n.NumberFormat.PATTERN_ZERO_DIGIT_ :
A zero digit character.
Code »
goog.i18n.NumberFormat.QUOTE_ :
A quote character.
Code »
goog.i18n.NumberFormat.enforceAsciiDigits_ :
If the usage of Ascii digits should be enforced.
Code »

Enumerations

goog.i18n.NumberFormat.CompactStyle :
Compacting styles.
Constants:
LONG
No description.
NONE
No description.
SHORT
No description.
Code »
goog.i18n.NumberFormat.CurrencyStyle :
Currency styles.
Constants:
GLOBAL
No description.
LOCAL
No description.
PORTABLE
No description.
Code »
goog.i18n.NumberFormat.Format :
Standard number formatting patterns.
Constants:
COMPACT_LONG
No description.
COMPACT_SHORT
No description.
CURRENCY
No description.
DECIMAL
No description.
PERCENT
No description.
SCIENTIFIC
No description.
Code »

Package i18n

Package Reference