You may know but make mistakes. Details determine success or failure. you may know that forced conversion will lose precision. you may know more or less similar details, and you may also have missed details.
1 + 1 = 2
3 * (1/3) = 1 Yes, but you can try it on the computer.
3*0. 3333... = 0.999999999! = 1
This is the details. When should I pay attention to the situation? for example, I pay attention to cash and interest rates.
"; Echo (int) (0.1 + 0.1) * 10); // 2 echo"
"; Echo (int) (0.1 + 0.7) * 10); // 7 echo"
"; Echo (0.1 + 0.7); // 0.8 echo"
"; Echo intval (0.1 + 0.7) * 10); // 7 instead of 8 echo"
"; Echo intval (bcadd (0.1, 0.7, 8) * 10 ); // 8 ++ ++, you may understand, but I still don't understand, because I am stupid, so I found php. Chm provides some explanations about the Warning of Warning on floating point precision. Obviously, the decimal score is as simple as 0.1 or 0.7. it cannot be converted to the internal binary format without losing a little bit of precision. This results in confusion: for example, floor (0.1 + 0.7) * 10) usually returns 7 instead of 8 in the expected result, because the internal representation of this result is similar to 7.9. This is related to the fact that it is impossible to accurately express certain decimal scores with limited digits. For example, the value of decimal 1/3 is 0.3. Therefore, never believe that the result of a floating point number is accurate to the last digit, or compare whether the two floating points are equal. If higher precision is required, use any precision mathematical function or gmp function. For any precision calculation above, refer to php. chm bcadd-Add two arbitrary precision numbers string bcadd (string $ left_operand, string $ right_operand [, int $ scale]).