PHP ROUND vs Javascript ROUND

后端 未结 5 1018
花落未央
花落未央 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:34

    console.log(Math.round(175.5)); // 176
    console.log(Math.round(-175.5)); // -175 <-why not -176!!??
    

    175.5 its round value 176 it's value increasing.

    -175.5 round value is -175. Because when I round -175.5 then it also increasing that means -175>-176.

提交回复
热议问题