Take a decimal number and convert it to its string representation
Take a decimal number and convert it to a string representation. For example if you have the number
2523.04, this module will convert
"Two thousand five hundred twenty-three and 04/100 dollars"
npm install -g number-string-representation
The module requires that you have the
npm binaries installed and available on your path. The latest version node.js is available here and includes the npm binary as well
As a command line tool
number-string-representation --number="2523.04"# outputs "Two thousand five hundred twenty-three and 04/100 dollars"
For usage of the command line tool execute the command with no option parameters specified
number-string-representation# prints out usage information
As a module within your own code. Note that you must pass a valid number as the input parameter to module function. String numbers will throw an exception
Valid input parameter example
var numberStringRepresentation = require'number-string-representation'var input = 2523.04var output = numberStringRepresentationinputconsole.log'output: %s' output
Invalid input parameter example
var numberStringRepresentation = require'number-string-representation'var input = '2523.04'var output = numberStringRepresentationinput // will throw an error hereconsole.log'output: %s' output
If you supply a negative number as an input, the output will be prepended with the text 'Negative '
var numberStringRepresentation = require'number-string-representation'var input = -2523.04// output === 'Negative two thousand five hundred twenty-three and 04/100 dollars'Ne output = numberStringRepresentationinputconsole.log'output: %s' output
When using negative numbers with the command line tool, you must pass them using both the equals sign and quotation marks around your value
number-string-representation --number="-2523.04"# outputs "Negative two thousand five hundred twenty-three and 04/100 dollars"
The following will not work and will instead throw an error. Note that the equals sign from the example above is missing here:
number-string-representation --number "-2523.04"
Currently the module only supports numbers in the range [-999999999999999, 999999999999999], which corresponds to negative trillions to positive trillions.
If you input a number with fractional cents, they will always be rounded down. For example
number-string-representation --number=".546"# will output "Zero and 54/100 dollars"
# install the development dependenciesnpm install# run the testsnpm test