Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round number down the to the nearest hundredth using php [duplicate]

Tags:

php

I'm probably not looking hard enough but the common question about php rounding is rounding up, not down.

For example I am trying round this..

<?php $roundDown = 768; ?>

Down to..

<?php var_dump($roundDown) /* 700 */ ?>

Whats the simplest method to do this, or is it because the number is closer to 800 that it's not technically rounding?

Whats the function that I need to do this if it's not rounding?

A little point in the right direction would be much appreciated.

like image 330
joshmoto Avatar asked Jan 27 '23 17:01

joshmoto


1 Answers

You can try ceil() and floor() function.

 echo floor(768 / 100) * 100;  // Output:700
 echo ceil(768 / 100) * 100;  // Output:800
like image 50
Mr.Gandhi Avatar answered Jan 30 '23 04:01

Mr.Gandhi