如何在PHP中将1e8值转换为普通整数?

时间:2018-11-08 00:06:27

标签: php

我有用1e8转换的整数值4567,它变为0.00004567,所以我的问题是如何在PHP中将其转换回4567?

1 个答案:

答案 0 :(得分:-2)

您可以使用number_format()例如

将其转换回

使用number_format($scientific, 0, '.', '');

<?php

function makeScientificNumber($number){
        $power = ($number % 10) - 1;
        return ($number / pow(10, $power)) . "e" . $power;
}

function makeNormalNumber($scientific){

    return number_format($scientific, 0, '.', '');
}

$number = 4567;
$scientific_number = makeScientificNumber($number);
echo "Scientific number is = $scientific_number";

echo PHP_EOL;

$normal_number = makeNormalNumber($scientific_number);
echo "Normal number is $normal_number";
?>

输出:

Scientific number is = 0.004567e6 

Normal number is 4567

演示: https://3v4l.org/jpUnV