如何在 PHP 中将指数转换为小数

2024-01-09

我有一个像这样的字符串:

  9.018E-14

现在我想将其转换为正常的十进制数。


我的极客伙伴 http://www.mygeekpal.com/how-to-convert-exponentials-to-decimals-in-php/有一篇关于它的好文章。

Code:

<?php
$total_time = 2.8848648071289E-5;

echo exp2dec($total_time);

function exp2dec($number) {
    preg_match('/(.*)E-(.*)/', str_replace(".", "", $number), $matches);
    $num = "0.";
    while ($matches[2] > 0) {
        $num .= "0";
        $matches[2]--;
    }
    return $num . $matches[1];
}
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 PHP 中将指数转换为小数 的相关文章

随机推荐