I encountered a strange problem recently. Orders paid through WeChat in the mall often cost one penny less. After troubleshooting, it was found to be caused by PHP floating point calculation precision issues
It is caused by the precision of PHP floating point number operations. Brother Niao’s Bolg has detailed instructions. http://www.laruence.com/2013/03/26/2884.html,
When decimals are expressed in binary, 0.58 is an infinite value in binary
0.58的二进制表示基本上(52位)是: 0010100011110101110000101000111101011100001010001111 0.57的二进制表示基本上(52位)是: 0010001111010111000010100011110101110000101000111101
Convert to floating point number (64-bit double precision)
0.58 -> 0.57999999999999996 0.57 -> 0.56999999999999995
0.58*100 = 57.999999999<span style="color: #000000;"> (int)(</span>0.58*100) = 57
Solution:
(int)((0.58*1000)/10) = 58