Javascript VS PHP rounding

后端 未结 6 739
轮回少年
轮回少年 2020-12-18 05:11

I am having some problems with the way PHP and javascript round numbers. I am using PHP\'s round function and this javascript function:



        
6条回答
  •  北荒
    北荒 (楼主)
    2020-12-18 05:40

    It is because the different precisions used in JS (by the browser) and PHP or actually how many bits are used to store the numbers.

    you can make your JS rounding function do this to round to the 2nd digit Math.round(floatNumber*100)/100

提交回复
热议问题