ToFixed (): converts a number to a string according to the specified number of digits after the decimal point. It does not use exponential counting
Toexponential(): converts a number to an exponential string according to the number of digits specified after the decimal point. There is only one digit before the decimal point, and the number of digits after the decimal point is specified by parameters
Toprecision(): converts a number to a string based on the number of significant digits. If the number of significant digits is less than the integer part of the number, it is expressed as an exponential string
The above three methods all follow the principle of “rounding off” or filling 0
Here are some examples:
var num = 1234567.8999; console.log("num.toFixed(0):" + num.toFixed(0)); console.log("num.toFixed(2)" + num.toFixed(2)); console.log("num.toFixed(5)" + num.toFixed(5)); console.log("num.toFixed(12)" + num.toFixed(12)); console.log("num.toExponential(3):" + num.toExponential(3)); console.log("num.toExponential(0):" + num.toExponential(0)); console.log("num.toPrecision(1):" + num.toPrecision(1)); console.log("num.toPrecision(5)" + num.toPrecision(5)); console.log("num.toPrecision(12)" + num.toPrecision(12));
Corresponding to the following output:
Similar Posts:
- [Solved] Division Error: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
- [Solved] BigDecimal division error: Non-terminating decimal expansion; no exact representable decimal result.
- java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal …
- How to Solve TypeError: not all arguments converted during string formatting
- Bridging mechanism of toll free bridging in IOS
- Settext notes of Textview (How to Use)
- IOS Upload Package Error: error itms-90478: invalid version [How to Solve]
- [Solved] Several Service Control Manager Issues (Event ID’s 7000, 7009, 7011)
- [Solved] Android.content.res.Resources$NotFoundException: String resource ID #0x0
- [Solved] Failed to convert property value of type ‘null‘ to required type ‘double‘ for property ‘balance‘