Number-Methods Flashcards
1
Q
toExponential
A
.toExponential(digit=most-specific) => {str} number in exponential form rounded to the nearest `digit` #safe
digit
- number of digits after the decimal point (last digit is rounded)
- if omitted, no rounding
- range 0 - 20, else throws RangeError
2
Q
toFixed
A
.toFixed(num digit=0) => {str} number w/ fixed-point notation #safe
digit
- number of digits after the decimal point to include (last digit is rounded), padded with 0’s if needed
- range 0 - 20, else throws RangeError
3
Q
toPrecision
A
.toPrecision(num precision=most-precise) => {str} number w/ precise number of digits, either fixed-point or exponential notation #safe
precision
- if omitted, .toPrecision() === .toString()
- range 0 - 100, else throws RangeError; however, older ES versions required up to 21, which some implementations still adhere to (V8).
4
Q
toString
A
.toString(num base=10) => {str} number at base of `base` #safe #example: (2).toString(2) => '10'
base
- range 2 - 36, else throws RangeError
- (2 - binary, 16 - hexadecimal, etc.)
5
Q
valueOf
A
.valueOf() => {num} primitive number value #safe