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

Rounding last decimal place to 0?

I tried round, ceil and floor, but they do not seem to do what I want (or I dont see the wood for the trees :-))

This is what I want:

1.44 --> 1.40
1.23 --> 1.20
3.50 --> 4.00
2.48 --> 2.50
...

I did not find a way to achieve that. Should be possible?

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

Thanks!

>Solution :

You can combine round() and number_format():

For example:

$number = 1.44;
number_format(round($number, 1), 2, '.', ''); // 1.40
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