PHP ROUND vs Javascript ROUND

后端 未结 5 1014
花落未央
花落未央 2021-01-13 16:12

I found a very strange issue, the issue is the ROUND method in PHP and Javascript the calculation results are not the same!?

See the following example:

PHP

5条回答
  •  有刺的猬
    2021-01-13 16:52

    Or... if you wanted JavaScript to behave the same as PHP, use this:

    function phpRound(number) {
      if(number < 0)
        return 0 - Math.round(0 - number);
      return Math.round(number);
    }
    

提交回复
热议问题