Topics PHP Basics Numbers & Math Operations
beginner 8 min read

Numbers & Math Operations

Integers, floats, mathematical functions, and number formatting.

Numbers in PHP

Integer & Float

\$a = 42;      // int
\$b = 3.14; // float
\$c = 0xFF; // hex (255)
\$d = 0b1010; // binary (10)

Math Functions

abs()
round()
ceil() / floor()
max() / min()
rand()
sqrt()
pow()
number_format()

Integer Overflow

PHP automatically converts to float when integers overflow, which depends on PHP_INT_MAX (usually 9223372036854775807 on 64-bit systems).

Examples

<?php
echo number_format(1234567.89, 2);
echo "\n";
echo rand(1, 100);
echo "\n";
echo ceil(4.2);

Your Notes

Sign in to take notes for this lesson.

Discussion

Sign in to join the discussion.

Flashcards

Sign in to create flashcards.