Friday, 17 June 2016

How to convert a negative number to a positive number using PHP

PHP comes with a built-in function called abs() [Absolute Value] to convert a negative number to positive number. It accepts one parameter the number itself. The number can be a integer or a float. If the parameter supplied to the function is float it will return float value. Otherwise, it will return an integer.
Examples:
<?php
echo abs(-6.2);  // 6.2 (float)
echo abs(19);    // 19 (integer)
echo abs(-2);    // 2 (integer)
?>

0 comments:

Post a Comment