Class Index | File Index

Classes


Class INumber

Parse a string as a number, ignoring all locale-specific formatting.

This class is different from the standard Javascript parseInt() and parseFloat() functions in that the number to be parsed can have formatting characters in it that are not supported by those two functions, and it handles numbers written in other locales properly. For example, if you pass the string "203,231.23" to the parseFloat() function in Javascript, it will return you the number 203. The INumber class will parse it correctly and the value() function will return the number 203231.23. If you pass parseFloat() the string "203.231,23" with the locale set to de-DE, it will return you 203 again. This class will return the correct number 203231.23 again.

The options object may contain any of the following properties:

This class is named INumber ("ilib number") so as not to conflict with the built-in Javascript Number class.
Defined in: INumber.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
INumber(str, options)
Method Summary
Method Attributes Method Name and Description
 
If the type of this INumber instance is "currency", then the parser will attempt to figure out which currency this amount represents.
 
Return the locale for this formatter instance.
 
Return the original string that this number instance was created with.
 
Return the value of this INumber object as a primitive number instance.
Class Detail
INumber(str, options)
Parameters:
{string|number|INumber|Number|undefined} str
a string to parse as a number, or a number value
{Object=} options
Options controlling how the instance should be created
Method Detail
{Currency|undefined} getCurrency()
If the type of this INumber instance is "currency", then the parser will attempt to figure out which currency this amount represents. The amount can be written with any of the currency signs or ISO 4217 codes that are currently recognized by ilib, and the currency signs may occur before or after the numeric portion of the string. If no currency can be recognized, then the default currency for the locale is returned. If multiple currencies can be recognized (for example if the currency sign is "$"), then this method will prefer the one for the current locale. If multiple currencies can be recognized, but none are used in the current locale, then the first currency encountered will be used. This may produce random results, though the larger currencies occur earlier in the list. For example, if the sign found in the string is "$" and that is not the sign of the currency of the current locale then the US dollar will be recognized, as it is the largest currency that uses the "$" as its sign.
Returns:
{Currency|undefined} the currency instance for this amount, or undefined if this INumber object is not of type currency

{Locale} getLocale()
Return the locale for this formatter instance.
Returns:
{Locale} the locale instance for this formatter

{string} toString()
Return the original string that this number instance was created with.
Returns:
{string} the original string

{number} valueOf()
Return the value of this INumber object as a primitive number instance.
Returns:
{number} the value of this number instance

Documentation generated by JsDoc Toolkit 2.4.0 on Thu Nov 15 2018 17:45:08 GMT-0800 (PST)