There is this function that is used tat I didn't myself create, but at the moment it is only returning the number rounded with 2 decimal places
, but I want to change it so it returns it with three; however I don't really understand how it all works.
Here is the function:
function round_number($number, $round = 2)
{
// we will multiply by 10^$round, then get the floor value of that amount then divide by 10^round.
## -> if it does problems, switch back to floor()
$temp_value = $number * pow(10, $round);
$temp_value = (!strpos($temp_value, '.')) ? $temp_value : floor($temp_value);
$number = $temp_value / pow(10, $round);
return $number;
}
I assume if I change the $round
to 3
that it will return correctly?
// we will multiply by 10^$round, then get the floor value of that amount then divide by 10^round.
## -> if it does problems, switch back to floor()
It says it right in the code what it does!
And yes - changing $round = 3;
will work.
However DON'T you should instead just call the function
round_number(12345.12342423, 3);
the number passed in as second parameter (3)
will override the $round=2
in the function ($round=2
is the 'default')