V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
OldActorsSmile
V2EX  ›  程序员

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

  •  
  •   OldActorsSmile · Oct 9, 2021 · 661 views
    This topic created in 1671 days ago, the information mentioned may be changed or developed.
    Number.prototype.toFloor = function (num) {
    	return Math.floor(this * Math.pow(10, num)) / Math.pow(10, num);
    }
    

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

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3636 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 00:38 · PVG 08:38 · LAX 17:38 · JFK 20:38
    ♥ Do have faith in what you're doing.