From the course: PHP Tips, Tricks, and Techniques

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Round numbers to a specific multiple

Round numbers to a specific multiple

From the course: PHP Tips, Tricks, and Techniques

Round numbers to a specific multiple

- [David] Hi, I'm David Powers and welcome to this week's edition of PHP Tips and Tricks designed to help you become a smarter, more productive PHP developer. In this edition, I want to look at rounding numbers. Not just to the closest integer, but to a specific multiple. This can be useful when resizing images for a website. The originals may be different sizes and it's often important to resize them to a specific size rather than to sum arbitrary figures to preserve the unity of the page layout. Let's start with the basics. You're probably familiar with these three built in PHP functions. By the way, you can follow along with the exercise files provided with this video. Round rounds up or down to the closest integer. Floor always rounds down. And ceil always rounds up. So passing this number 98.6 to each of these functions produces these results. We round up to 99. Floor rounds down to 98. And ceil rounds up to 99. Now let's switch to this other file. A slightly more complicated…

Contents