PHP Numbers & Math

Integers, floats and math functions.

✍️ 2 exercises in this lesson

PHP numbers are int or float. Useful functions:

  • is_int(), is_float(), is_numeric()
  • round(), ceil(), floor(), abs()
  • max(), min(), sqrt(), pow(), pi()
  • rand(1, 6) / random_int(): random numbers
  • intdiv() and %: integer division and remainder
  • number_format(): format with thousands separators

Key Takeaways: PHP Numbers & Math

Mastering PHP Numbers & Math helps you write clean and reliable PHP code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

PHP Numbers & Math Code Example

PHP
<?php
echo round(3.567, 2) . "<br>";
echo max(4, 19, 7) . " " . min(4, 19, 7) . "<br>";
echo sqrt(81) . "<br>";
echo intdiv(17, 5) . " remainder " . 17 % 5 . "<br>";
echo number_format(2500000) . "<br>";
var_dump(is_numeric("12.5"));
Output
3.57
19 4
9
3 remainder 2
2,500,000
bool(true)
Run this example on your own computer. The "Get Started" lesson shows how to set it up.

PHP Numbers & Math Practice Exercises

Check what you learned in “PHP Numbers & Math”.

/ 2 solved
Fill in the blank

Round 3.567 to 2 decimals.

echo (3.567, 2);
✓ Correct! Not quite. Try again.
Multiple choice

Which function formats 2500000 as "2,500,000"?

✓ Correct! Not quite. Try again.
to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services