Home  >  Article  >  Backend Development  >  php如何将一个未知数转换为Integer整数

php如何将一个未知数转换为Integer整数

WBOY
WBOYOriginal
2016-06-13 11:10:161133browse

php怎么将一个未知数转换为Integer整数
初学php,遇到点小问题不明白,忘各位多给我点指导,谢谢!

<br /><?php<br />echo ((0.1+0.7)*10)              //显示8<br />echo?(int)((0.1+0.7)*10);?       //怎么显示显示?7 ?<br />echo intval(((0.2+0.7)*10));     //取整数9,是正确的<br />echo intval(((0.1+0.7)*10));     //怎么又显示 7 ?<br />echo (integer)(((0.1+0.7)*10));  //还是 7 ?<br />?><br />


请问到底是怎么将类似((0.1+0.7)*10)的一个表达式的结果(整数或浮点数) 转为整数呢?

php
------解决方案--------------------
浮点数的精度问题

$n = ((0.1+0.7)*10); 
printf("%.16f %d\n", $n, $n);

7.9999999999999991 7
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