How to realize floating-point Operation in php
Editor to share with you how to achieve floating-point operations in php, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
The details are as follows:
When doing e-commerce, it is inevitable to calculate the price, and then I found a pit in php. The mental calculation should be correct, and the php calculation will be different from yours.
Take a look at the following code:
$price=69.1;$count=100;$total=$price*$count-6910;echo $total
Guess what the value of the variable $total is, and run this code to output:-9.09494701773E-13
How to solve this problem?
Use the round function
The code is modified to:
$price=69.1;$count=100;$total=round ($price*$count)-6910 bot echo $total
The problem is solved, and the output is 0, which is correct.
These are all the contents of the article "how to implement floating-point operations in php". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!