1. ToFixed is rounded to two decimal places
ToFixed (2) == 1.33
2. Implement the two-digit decimal scheme
- Regular match
// Truncate N decimal places (directly after discarding the specified number of digits); Number.prototype.cutFixed = function(digit = 2) { let reg = new RegExp(`^\\d+(? :\\.\\d{0,${digit}})? `); return Number(this.toString().match(reg)); }; (9.9999). CutFixed (2) = > 9.99Copy the code
- Use math.floot (num * 100)/100
⚠️ In this scenario, math.floor () is prone to accuracy problems
Math. Floor (8.54 * 100) / 100 = > 8.53
- String manipulation. With regular