How do I round up on PHP?

3

What is PHP's function for rounding off excess?

Example:

1.1 pass 2

    
asked by anonymous 02.10.2015 / 16:00

4 answers

5

Use the ceil() function.

echo ceil(1.1);

See working on ideone .

    
02.10.2015 / 16:01
2
<?php
echo ceil(1.1);  // 2
echo ceil(4.3);    // 5
echo ceil(9.999);  // 10
echo ceil(-3.14);  // -3
?>
    
02.10.2015 / 16:04
2

Use the ceil function.

ceil(1.1); // Imprime 2

This function is usually used to know the number of pages that will be generated in pagination.

Example:

$total = 100;
$limit = 12;
$pages = ceil($total / $limit); // Imprime 9

It serves to round fractions upwards.

Just to have you add information: The counter function is floor . It rounds down.

    
02.10.2015 / 16:01
2

In PHP for overcharging, use the ceil function.

Example

echo ceil(4.3);    // 5
    
02.10.2015 / 16:01