The abs() function returns absolute value of given number. It returns an integer value but if you pass floating point value, it returns a float value.
number abs ( mixed $number )
<?php
echo (abs(-7)."<br/>"); // 7 (integer)
echo (abs(7)."<br/>"); //7 (integer)
echo (abs(-7.2)."<br/>"); //7.2 (float/double)
?>
Output:
7
7
7.2
The ceil() function rounds fractions up.
float ceil ( float $value )
<?php
echo (ceil(3.3)."<br/>");// 4
echo (ceil(7.333)."<br/>");// 8
echo (ceil(-4.8)."<br/>");// -4
?>
Output:
4
8
-4
PHP Math: floor() function
The floor() function rounds fractions down.
float floor ( float $value )
<?php
echo (floor(3.3)."<br/>");// 3
echo (floor(7.333)."<br/>");// 7
echo (floor(-4.8)."<br/>");// -5
?>
Output:
3
7
-5
The sqrt() function returns square root of given argument.
float sqrt ( float $arg )
<?php
echo (sqrt(16)."<br/>");// 4
echo (sqrt(25)."<br/>");// 5
echo (sqrt(7)."<br/>");// 2.6457513110646
?>
Output:
4
5
2.6457513110646
The decbin() function converts decimal number into binary. It returns binary number as a string.
string decbin ( int $number )
<?php
echo (decbin(2)."<br/>");// 10
echo (decbin(10)."<br/>");// 1010
echo (decbin(22)."<br/>");// 10110
?>
Output:
10
1010
10110
The dechex() function converts decimal number into hexadecimal. It returns hexadecimal representation of given number as a string.
string dechex ( int $number )
<?php
echo (dechex(2)."<br/>");// 2
echo (dechex(10)."<br/>");// a
echo (dechex(22)."<br/>");// 16
?>
Output:
2
a
16
The decoct() function converts decimal number into octal. It returns octal representation of given number as a string.
string decoct ( int $number )
<?php
echo (decoct(2)."<br/>");// 2
echo (decoct(10)."<br/>");// 12
echo (decoct(22)."<br/>");// 26
?>
Output:
2
12
26
The base_convert() function allows you to convert any base number to any base number. For example, you can convert hexadecimal number to binary, hexadecimal to octal, binary to octal, octal to hexadecimal, binary to decimal etc.
string base_convert ( string $number , int $frombase , int $tobase )
<?php
$n1=10;
echo (base_convert($n1,10,2)."<br/>");// 1010
?>
Output:1010
The bindec() function converts binary number into decimal.
number bindec ( string $binary_string )
<?php
echo (bindec(10)."<br/>");// 2
echo (bindec(1010)."<br/>");// 10
echo (bindec(1011)."<br/>");// 11
?>
Output:
2
10
11
© 2024 Easy To Learning. All Rights Reserved | Design by Easy To Learning