11

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.

joshmoto
  • 4,472
  • 1
  • 26
  • 45

1 Answers1

27

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

 echo floor(768 / 100) * 100;  // Output:700
 echo ceil(768 / 100) * 100;  // Output:800
Nikhil G
  • 2,096
  • 14
  • 18
  • 1
    Just figured it exact same way using this https://stackoverflow.com/questions/1619265/how-to-round-up-a-number-to-nearest-10 but solid answer.. so simple. Need to work on my math. Thanks dude – joshmoto Feb 18 '19 at 04:17