Convert a base-10 or scientific E-notation value to a decimal form string.
This method converts a base-10 or scientific E-notation value to
a decimal form string. Javascript's IEE 754 double-precision numbers
give the same precision as number.toString()
.
Kind: Exported function
Returns: string
- The value converted to a decimal form string.
Throws:
TypeError
If value is not a valid format.TypeError
If value is a Symbol or not coercible.
Param | Type | Description |
---|---|---|
value | number | string |
The value to be converted. |
Example
import toDecimalFormString from 'number-to-decimal-form-string-x';
toDecimalFormString(Number.MIN_SAFE_INTEGER); // '-9007199254740991'
toDecimalFormString(-0); // '-0'
let number = 0.00000000001;
number.toString(); // '1e-11'
toDecimalFormString(number); // '0.00000000001'
number = 88259496234518.57;
console.log(number.toString()); // '88259496234518.56';
console.log(toDecimalFormString(number)); // '88259496234518.56'
console.log(toDecimalFormString(Math.PI)); // '3.141592653589793'
console.log(toDecimalFormString(Number.MAX_SAFE_INTEGER)); // '9007199254740991'
console.log(toDecimalFormString('0e+0')); // '0'
console.log(toDecimalFormString('1e-11')); // '0.00000000001'
console.log(toDecimalFormString('4.062e-3')); // '0.004062'
console.log(toDecimalFormString('4.461824e+2')); // '446.1824'
toDecimalFormString(NaN); // TypeError
toDecimalFormString(' 0'); // TypeError
toDecimalFormString('0 '); // TypeError
toDecimalFormString('0.'); // TypeError
toDecimalFormString('.0'); // TypeError
toDecimalFormString('0x1'); // TypeError
toDecimalFormString('0o1'); // TypeError
toDecimalFormString('0b1'); // TypeError
toDecimalFormString('4.062 e-3'); // TypeError
toDecimalFormString('9 007 199 254 740 991'); // TypeError
toDecimalFormString('9,007,199,254,740,991'); // TypeError
toDecimalFormString(Symbol('0')); // TypeError
toDecimalFormString(Object.create(null)); // TypeError