下面的代码应该是格式化我在mysql中运行乘法以获取临时表中的数据后得到的数字。问题是乘法的结果没有遵循格式。我想把数字格式化为四位小数,保留零。
<?php $tv = $row_cscs_report['TOTAL_VALUE']; $vr = str_replace('.', '', $tv); echo $vr; ?>
bxjv4tth1#
你可以这样写:
<?php $tv = $row_cscs_report['TOTAL_VALUE']; $vr = sprintf("%.4f", $tv); echo $vr; ?>
参考文献:http://php.net/manual/pl/function.sprintf.php
x9ybnkn62#
你可以使用 number_format ,指定4个小数位,并告诉它小数点和千位分隔符都应为空:
number_format
$tv = 3547.66; echo number_format($tv, 4, '', '');
输出:
35476600
2条答案
按热度按时间bxjv4tth1#
你可以这样写:
参考文献:http://php.net/manual/pl/function.sprintf.php
x9ybnkn62#
你可以使用
number_format
,指定4个小数位,并告诉它小数点和千位分隔符都应为空:输出: