Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I round 4.3 to 4.5

Tags:

php

Given a value that has 1 decimal place, how do I round that decimal place up a half step?

If I have a value of, say, 4.3, how do I round that in PHP to 4.5?

Other examples would be:

3.8 >> 4.0
2.1 >> 2.5
0.9 >> 1.0

Also I should mention that I am running PHP version 5.2.17

Thanks!

like image 727
Industrial Themes Avatar asked Nov 17 '25 05:11

Industrial Themes


1 Answers

How about something like this?

<?php
    $value=10000.1;
    echo ceil($value*2)/2 . "\n";
?>
like image 179
finity Avatar answered Nov 19 '25 20:11

finity



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!