• 请不要在回答技术问题时复制粘贴 AI 生成的内容
OldActorsSmile
V2EX  ›  程序员

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

  •  
  •   OldActorsSmile · Oct 9, 2021 · 679 views
    This topic created in 1676 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   ·   6019 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 67ms · UTC 02:01 · PVG 10:01 · LAX 19:01 · JFK 22:01
    ♥ Do have faith in what you're doing.