How can you round a number up or down in PHP?
To round a number up or down in PHP, you can use the built-in functions `ceil()` to round up and `floor()` to round down. `ceil()` will always round up to the nearest whole number, while `floor()` will always round down to the nearest whole number.
// Round a number up
$number = 4.3;
$roundedUp = ceil($number);
echo $roundedUp; // Output: 5
// Round a number down
$number = 4.8;
$roundedDown = floor($number);
echo $roundedDown; // Output: 4
Keywords
Related Questions
- Why is it recommended to use variables instead of directly inserting values into SQL query strings in PHP?
- How can Iterator classes be effectively utilized in PHP applications?
- How can developers ensure that their PHP code using the Facebook PHP SDK adheres to the platform's rules and regulations regarding permissions and data sharing?