In this paper, we analyze some of the frustrating floating-point arithmetic in PHP. Share to everyone for your reference, specific as follows:
In the electrical business, the calculation price is unavoidable, and then found a hole in PHP, multi-digit should be the correct value, PHP operation will not be the same as you
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, run this code output: -9.09494701773E-13
How to solve this problem?
Using the ROUND function
Code modified to:
$price =69.1;
$count =100;
$total =round ($price * $count) -6910;
Echo $total;
The problem is solved, the output is 0, correct.
More about PHP Interested readers can view the site topics: "PHP Mathematical Arithmetic Skills summary", "PHP array" operation Skills Daquan, "PHP Sorting algorithm Summary", "PHP commonly used traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", " PHP Programming algorithm Summary, "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP string (String) Usage summary" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.