For instance I have the number float(450250000)
, (~450 Million) I would need this number int(500000000)
(500 Million).
Is there something PHP can do to determine this number no matter what is the scale of the number?
For instance I have the number float(450250000)
, (~450 Million) I would need this number int(500000000)
(500 Million).
Is there something PHP can do to determine this number no matter what is the scale of the number?
As Yash Mehta suggested you can do this:
function count_digit($number) {
return strlen((string) $number);
}
$number = 256789;
$number_of_digits = count_digit($number);
echo round($number, - ($number_of_digits - 1));
this will output 30000
.
round
is php function. You can find its documentation here.