Home >>PHP Tutorial >PHP Numeric Functions
Don't think that PHP's power is limited to strings only.
The language has over 50 built-in functions for working with numbers, ranging from simple formatting functions to functions for arithmetic, logarithmic, and trigonometric manipulations.
Some of these important functions areSr. No | Function | What it Does |
1 | ceil() | Rounds a number up |
2 | floor() | Rounds a number down |
3 | abs() | Finds the absolute value of anumber |
4 | pow() | Raises one number to the power of another |
5 | exp() | Finds the exponent of a number |
6 | rand() | Generates a random number |
7 | bindec() | Converts a number from binary to decimal |
8 | decbin() | Converts a number from decimal to binary |
9 | decoct() | Converts a number from decimal to octal |
10 | octdec() | Converts a number from octal to decimal |
11 | dechex() | Converts a number from decimal to hexadecimal |
12 | hexdec() | Converts a number from hexadecimal to decimal |
13 | number_format() | Formats number with grouped thousands and decimals |
14 | printf() | Formats a number using a custom specification |
15 | round | find round number |
16 | sqrt | find square root of a number |
<?php $num=19.7 echo ceil($num); ?>
<?php $num=19.7 echo floor($num); ?>
<?php $num =-19.7 echo abs($num); ?>
<?php echo pow(4,3); ?>
<?php echo rand(10,99); ?>
<?php echo bindec(1000); ?>
<?php echo decbin(8); ?>