【发布时间】:2018-10-13 18:28:20
【问题描述】:
我有一种情况,我将双变量转换为整数。它给了我错误的结果。为什么会这样?
>>> $amount = (double) 1052.10
=> 1052.1
>>> $amount = $amount * 100;
=> 105210.0
>>> (int) $amount;
=> 105209 // weird
我可以通过先对变量进行四舍五入来修复它(即:(int) round($amount)),
但是,我想知道为什么会这样?
使用 PHP 7.2.9
【问题讨论】: