PHP的float转int精度问题

xiaoxiao2021-02-28  25

地址:http://php.net/manual/zh/language.types.integer.php

<?php echo (int) ( (0.1+0.7) * 10 ); // 显示 7! ?>

解释: 

由于浮点数的精度问题,导致0.1+0.7=0.799999...,×10之后得7.9...,float转换成int时去掉尾数取整,所以结果为7。

转载请注明原文地址: https://www.6miu.com/read-1599996.html

最新回复(0)