In excel rounddown, rounddown(6432737, -7) = 6430000 rounddown(3456484, -7) = 3450000
How can I do it in PHP?
Please, I appreciate your ideas and answers.
I tried with floor in PHP but it doesn't work.
CodePudding user response:
You can use the floor function in PHP to round down a number to the nearest multiple of a power of 10. For example:
$rounded = floor(6432737 / 10000000) * 10000000; // $rounded will be 6430000
$rounded = floor(3456484 / 10000000) * 10000000; // $rounded will be 3450000
The floor function rounds down a number to the nearest integer, so you can use it to round down a number to the nearest multiple of any number. In the example above, we are dividing the number by 10,000,000 and then multiplying it by 10,000,000 to get the original number rounded down to the nearest multiple of 10,000,000.
You can also use the round function with a negative value for the second argument to achieve the same result:
$rounded = round(6432737, -7);
// $rounded will be 6430000
$rounded = round(3456484, -7);
// $rounded will be 3450000