SyntaxStudy
Sign Up
PHP Beginner 1 min read

PHP Math Functions

PHP Math Functions

FunctionDescription
abs($n)Absolute value
round($n,$dec)Round
floor($n)Round down
ceil($n)Round up
max($a,$b,...)Maximum
min($a,$b,...)Minimum
rand($min,$max)Random int
sqrt($n)Square root
pow($base,$exp)Power
pi()π value
Example
<?php
echo abs(-42);           // 42
echo round(3.567, 2);    // 3.57
echo floor(4.9);         // 4
echo ceil(4.1);          // 5
echo max(3, 7, 1, 9);   // 9
echo min(3, 7, 1, 9);   // 1
echo rand(1, 100);       // random 1-100
echo sqrt(144);          // 12
echo pow(2, 10);         // 1024
echo number_format(1234567.89, 2, ".", ","); // 1,234,567.89
?>