PHP5.2.17在计算小数时的有关问题

WBOY
Release: 2016-06-13 13:22:20
Original
930 people have browsed it

PHP5.2.17在计算小数时的问题,求救
$v['closed_price'] = 15.05;
$v['f_forecast_price'] = 14.68;
$diff = floatval($v['closed_price'] - $v['f_forecast_price']);
$closed_1 = floatval($v['closed_price']) * 0.1;
$rate = ($closed_1 - $dff) / $closed_1 ;

var_dump($closed_1 - $dff, $diff, $rate);


为什么$closed_1 - $dff是对的,但($closed_1 - $dff) / $closed_1得到一个1呢??

理论上应该是小数才对。

为啥呢???

------解决方案--------------------
太不仔细了

$diff = floatval($v['closed_price'] - $v['f_forecast_price']);
$closed_1 = floatval($v['closed_price']) * 0.1;
$rate = ($closed_1 - $dff) / $closed_1 ;

var_dump($closed_1 - $dff, $diff, $rate);

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!