Home > Backend Development > PHP Tutorial > php int处理的异常,如何解释

php int处理的异常,如何解释

PHPz
Release: 2018-09-28 10:47:34
Original
1198 people have browsed it

如下代码

$qty = 50.852;
echo (int) ($qty * 10000);

// 期望结果:508520
// 实际结果:508519
Copy after login
Copy after login

以上问题如何解释?并且如何处理会得到期望结果?

回复内容:

如下代码

$qty = 50.852;
echo (int) ($qty * 10000);

// 期望结果:508520
// 实际结果:508519
Copy after login
Copy after login

以上问题如何解释?并且如何处理会得到期望结果?

原来的答案不对,删除,补充题目相关内容如下:

$qty = 50.852;
echo $qty * 10000; //508520
echo (int) ($qty * 10000); //508519
echo round($qty * 10000); //508520
echo (int)($qty * 100000); //5085200
echo (int)($qty * 1000); //50852
echo (int)(508520); //508520
echo (int)50.852; //50
Copy after login

点击这里
你可以看下鸟哥对于浮点数的解释。

Related labels:
php
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template