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

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

  •  
  •   OldActorsSmile · Oct 9, 2021 · 728 views
    This topic created in 1702 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   ·   917 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 22:37 · PVG 06:37 · LAX 15:37 · JFK 18:37
    ♥ Do have faith in what you're doing.