Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I do in PHP to be similar to Excel Rounddown Formula

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried with floor in PHP but it doesn’t work.

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading