PHP Round up | How to round up value in PHP with Example?

Summary: in this article, you will learn about PHP Round up with an example and How to round the value in PHP with Example? Let’s understand and look at rounding numbers with using the following function such as-

  • round()
  • number_format()
  • ceil()
  • floor()
  • s/printf()


The PHP round() function is used to rounds the number passed into the specified number of decimal places. If the decimal place is a negative number then the numbers to the left of the decimal place are rounded. furthermore, if the decimal places parameter isn’t passed in then it defaults to 0(zero) and will round as an integer. five is round up and < 5 is rounded down.

From PHP 5.3.0 round() accepts a 3rd parameter can be passed that specifies the rounding mode and is one of


It defaults to PHP_ROUND_HALF_UP to keep up or maintain backward compatibility.

PHP number_format()

The number_format() function in PHP is used for formatting numbers with decimal places and thousands of separators, but it also rounds numbers if there are more decimal places in the original number than required. such as round(), it’ll round-up on five(5) and down on < 5.


The ceil() function in PHP rounds-up to the nearest integer (i.e. ceil = ceiling). There’s no argument for precision thus it’ll always round up to the nearest integer. If the number is already an integer then the value returned will remain the equivalent or the same.


The PHP floor() function works the same way as ceil() but always rounding down to the nearest integer. let’s see some examples:

printf() and sprintf()

The printf() and sprintf() functions in PHP are also for formatting and again will round numbers as well. printf() outputs the value to standard output whereas sprintf() returns it as a value.

PHP round up Related Question and Answer:

Question1: Do you round up at 5 or 6?

Answer: Here’s also we follow the round-up general rule for rounding: If the number you’re rounding is followed by 5, 6, 7, 8, or 9, round the number up. for Example such as 39 rounded to the nearest ten is 40. furthermore, If the number you’re rounding is followed by 0, 1, 2, 3, or 4, round the number down.

Question2: How do I round to 2 decimal places in PHP?

Answer: for the round to 2 decimal places in PHP, you can use the PHP number_format() function. This will show exactly two digits after the decimal point. The main Advantage: If you would like to display two digits after a float value only and not for int, then use this.

PHP round up conclusion:

In this article, you have learned round-up different function, which is used to round the numbers with example. I hope you will enjoy it!. if have any query then contact on I will try to resolve the problem.