zoukankan      html  css  js  c++  java
  • (xxx.55).toFixed(1) 无法正确进位处理

    参考:https://juejin.im/post/5a11a9fef265da43284073b4?utm_medium=fe&utm_source=weixinqun

    根本原因在于2.55的存储要比实际存储小一点,导致0.05的第1位尾数不是1,所以就被舍掉了。

    if (!Number.prototype._toFixed) {
        Number.prototype._toFixed = Number.prototype.toFixed;
    }
    Number.prototype.toFixed = function(n) {
        return (this + 1e-14)._toFixed(n);
    };
  • 相关阅读:
    4.26上午
    4.25下午
    4.19上午
    4.18上午
    7.26
    7.25
    7.21-7.22
    7.22
    7.21
    7.11-7.15
  • 原文地址:https://www.cnblogs.com/xtreme/p/8241356.html
Copyright © 2011-2022 走看看