有这样的mysql查询SELECT CurrencyRate/Units AS FinalCurrencyRate
CurrencyRate
的值0.06200000
,Units
的值1000
。
所以0.06200000
/1000
并得到6.2E-5
如果echo $result = 0.06200000 / 1000 . '<br>';
,则结果相同
如果echo $result = number_format( (0.06200000 / 1000), 10, '.', '' ) . '<br>';
那么可以得到0.0000620000
mysql查询获取正常数字而不是6.2E-5
的解决方案是什么?
找到round(CurrencyRate/Units,10)
但是,如果不知道小数点后的00000
数怎么办?例如0.06200000
/1000000000000000000
对此类值使用 DECIMAL 类型。这将使您的值以您提到的方式显示。
由于您使用的是货币,因此请使用 BC 数学函数以获得更好的清晰度。使用时,您可以设置结果中小数位后的位数。例:
//bcdiv - it divides to numbers
echo bcdiv('105', '6.55957', 3); // 16.007