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

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

  •  
  •   OldActorsSmile · 2021년 10월 9일 · 796 조회수
    1738일 지난 토픽입니다. 언급된 정보가 변경되었을 수 있습니다.
    Number.prototype.toFloor = function (num) {
    	return Math.floor(this * Math.pow(10, num)) / Math.pow(10, num);
    }
    

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

    아직 댓글이 없습니다
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5814 온라인   최고 기록 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 02:06 · PVG 10:06 · LAX 19:06 · JFK 22:06
    ♥ Do have faith in what you're doing.