问题
I have large numbers and their decimals points. Here are some examples and what should return:
Number: 300000
Decimals: 8
Should return: 0.00300000
Number: 700000000
Decimals: 8
Should return: 7
Number: 800000000
Decimals: 6
Should return: 800
At the moment I'm doing this:
substr($number, 0, abs($decimals + 1))
But it returns 0 if the number of decimals is superior to the number of digits in the number (example one returns 0).
Any idea how to do this?
回答1:
Divide by 10 to the power of the number of decimals:
$result = $number / (10 ** $decimals);
回答2:
Divide by ten to the power of decimals?
$n = 700000000;
$d = 8;
Echo $n/pow(10,$d);
https://3v4l.org/MdoW1
来源:https://stackoverflow.com/questions/47143473/moving-decimal-from-the-right-in-php