V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
OldActorsSmile
V2EX  ›  程序员

[JS] Number.prototype.toFloor 有什么坑?

  •  
  •   OldActorsSmile · 2021-10-09 23:14:22 +08:00 · 349 次点击
    这是一个创建于 942 天前的主题,其中的信息可能已经有所发展或是发生改变。
    Number.prototype.toFloor = function (num) {
    	return Math.floor(this * Math.pow(10, num)) / Math.pow(10, num);
    }
    

    js 自带的保留 n 位小数.toFixed 是进一法。 网上找去尾法,找到上述那个,但是博客主形容它为“批评疯传已久的去尾法”,但是没给原因。 有大神知道什么原因吗?

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   6151 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 01:48 · PVG 09:48 · LAX 18:48 · JFK 21:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.