new numberstowords()
The numberstowords singleton class.
Properties:
Name | Type | Description |
---|---|---|
words |
numberstowords.Words | The actual words used for conversion. These can be replaced, but at your own risk. Please set them in lower case. |
options |
numberstowords.Opts | The default options for conversion. If you set the options through this property, all subequent calls to the methods will use the new options by default. The resetOptions() method can be used to reset to the library defaults. |
- Source:
Methods
resetOptions()
Resets the global options to the library defaults
- Source:
toIndianWords(number, opts) → {string}
Converts numbers to words, Indian style
Parameters:
Name | Type | Description |
---|---|---|
number |
number | the number to convert |
opts |
numberstowords.Opts | options for conversion. The useIndianStyle option will be set to true. |
- Source:
Returns:
- the number converted to words
- Type
- string
toInternationalWords(number, opts) → {string}
Converts numbers to words, international style
Parameters:
Name | Type | Description |
---|---|---|
number |
number | the number to convert |
opts |
numberstowords.Opts | options for conversion. The useIndianStyle option will be set to false. |
- Source:
Returns:
- the number converted to words
- Type
- string
toWords(number, opts) → {string}
Converts numbers to words
Parameters:
Name | Type | Description |
---|---|---|
number |
number | the number to convert |
opts |
numberstowords.Opts | options for conversion |
- Source:
Returns:
- the number converted to words
- Type
- string
Type Definitions
Opts
The Opts object defines options available while converting to words.
Properties:
Name | Type | Description |
---|---|---|
integerOnly |
boolean | if true, rounds of number to the nearest integer before converting. If false, converts decimal numbers like this: 1.12 becomes 'one point one two', unless the useCurrency option is true. Default: true. |
useComma |
boolean | if true, puts a comma after each "large" number group. E.g. 1101 becomes 'one thousand, one hundred one'. Default: false. |
useAnd |
boolean | if true, puts the 'and' word between hundreds and unit words. Eg. 1101 becomes 'one thousand, one hundred and one'. Default: false. |
useOnlyword |
boolean | if true, puts the 'only' word at the end. Eg. 12 becomes 'twelve only'. Default: false. |
useIndianStyle |
boolean | if true, numbers greater than 99999 are grouped using the Indian units lakhs and crores. If false, they are grouped using millions, billions and trillions. Default: true. |
useCurrency |
boolean | if true, uses the major (and minor if intergeOnly is false) currency symbols as described below. |
majorCurrencySymbol |
string | the major currency symbol, like 'dollar' or 'ringgit'. Default: 'rupees'. |
minorCurrencySymbol |
string | the minor currency symbols, like 'cents' or 'sen'. Default: 'paise'. |
majorCurrencyAtEnd |
string | if false, the major currency symbol is at the start of the words, e.g. 2 becomes 'rupees two'. If true, e.g. 2 becomes 'two rupees'. Default: false. |
minorCurrencyAtEnd |
string | if false, the minor currency symbol is at the start of the appropriate part, e.g. 2.22 becomes 'rupees two and paise twenty two'. If true, e.g. 2.22 becomes 'rupees two and twenty two paise'. Not that the 'and' word will always be used between the major and minor currency parts. Default:true. Default: false. |
suppressMajorIfZero |
boolean | if true, will not convert the major part two words if it is zero. E.g. 0.22 will become 'twenty two paise'. If false, 0.22 will become 'rupees zero and twenty two paise'. Default false. |
useCase |
string | the casing of the words. Possible values are 'lower', 'upper', 'proper' and 'sentence'. If you pass an Opts object as the second parameter of any conversion function, the options you provide will be combined with the global options in numberstowords.options. |
- Source:
Words
The Words object defines the words that are used in conversion.
Properties:
Name | Type | Description |
---|---|---|
unitWords |
Array.<string> | describes the "unit" words, zero to nineteen. Array indices match the word. E.g.: unitWords[0] is 'zero' |
tenWords |
Array.<string> | describes the "tens" words, twenty to ninety. Array indices match the factor of ten. E.g.: unitWords[3] is 'thirty'. The first two indices should be null. |
smallAmountWords |
Object.<string, string> | words for "small" large amounts. The keys are "hundred" and "thousand". |
bigAmountWords |
Object.<string, string> | words for "big" large amounts. The keys are "lakh", "crore", "million", "billion" and "trillion". |
andWord |
string | word used for joining hundreds with units, and joining the integer part with decimal part. Default is 'and'. |
pointWord |
string | word used for describing the decimal part in the international format. Default is 'point', as in 'one point five'. |
onlyWord |
string | word used for describing the end of an amount. Default is 'only'. |
- Source: