Home  >  Article  >  Backend Development  >  [PHP floating point number problem] What is the reason for the following PHP code output?

[PHP floating point number problem] What is the reason for the following PHP code output?

WBOY
WBOYOriginal
2016-07-21 18:01:32764browse

The comments are the output of this line. You can see that when the single digits of the floating point number are 6, 7, 8, or 9, the output results are not as expected.
var_dump(intval("10.40"*100)); // 1040
var_dump(intval("11.40"*100)); // 1140
var_dump(intval("12.40"*100)) ; // 1240
var_dump(intval("13.40"*100)); // 1340
var_dump(intval("14.40"*100)); // 1440
var_dump(intval("15.40" *100)); // 1540
var_dump(intval("16.40"*100)); // 1639
var_dump(intval("17.40"*100)); // 1739
var_dump(intval ("18.40"*100)); // 1839
var_dump(intval("19.40"*100)); // 1939

Reply content:

First read All ‘bogus’ about the float in PHP
Then read: Answers to a common question about PHP floating point numbers See here for a detailed explanation:
0.30000000000000004 The reason is that binary cannot accurately represent decimals such as 1/10, etc. This problem exists in all languages ​​​​that use the IEEE754 standard to store floating point content.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn