Search w3schools.com:

SHARE THIS PAGE

PHP round() Function


PHP Math Reference Complete PHP Math Reference

Definition and Usage

The round() function rounds a number to the nearest integer.

Syntax

round(x,prec)

Parameter Description
x Required. The number to be round
prec Optional. The number of digits after the decimal point


Example

In this example we will round different numbers with the round() function:

<?php
echo(round(0.60) . "<br />");
echo(round(0.50) . "<br />");
echo(round(0.49) . "<br />");
echo(round(-4.40) . "<br />");
echo(round(-4.60))
?>

The output of the code above will be:

1
1
0
-4
-5


PHP Math Reference Complete PHP Math Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]