JavaScript Number Methods
JavaScript Number Methods
- These number methods can be used on all JavaScript numbers.
Method | Description |
---|---|
toString() | Returns a number as a string |
toExponential() | Returns a number written in exponential notation |
toFixed() | Returns a number written with a number of decimals |
toPrecision() | Returns a number written with a specified length |
ValueOf() | Returns a number as a number |
The toString() Method
- The toString() method returns a number as a string.
- All number methods can be used on any type of numbers (literals, variables, or expressions)
Sample Code
Output
The toExponential() Method
- toExponential() returns a string, with a number rounded and written using exponential notation.
- A parameter defines the number of characters behind the decimal point.