3

How can I use round() to round a number to the superior number as soon as there is a decimal?

For example:

1.00001      = 2
1.1          = 2
1.4785834975 = 2
1.00         = 1
1.99         = 2
3.01         = 4
Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
456543646346
  • 973
  • 4
  • 15
  • 22

2 Answers2

7

Yes, what you are looking for is called ceil

<?php
echo ceil(4.3);    // 5
echo ceil(9.999);  // 10
echo ceil(-3.14);  // -3
?>
Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504
3

This might be helpful for you:

floor() will go down.

ceil() will go up.

round() will go to nearest by default.

<?php
echo ceil(3.4);    // 4
echo ceil(8.89);  // 9
?>
Vijaya Pandey
  • 4,252
  • 5
  • 32
  • 57