Faster PHP Cloud Hosting

The php abs function is a part of php math and is usually used to convert negative numbers to positive numbers. Basically it gives you the absolute value of a number.


    echo (abs("-5.25")."\n"); 
    echo (abs("5.25")."\n"); 
    echo (abs("-5")."\n"); 
    echo (abs("5")."\n"); ?>


// Output

Definition And Usage Of the abs function

The abs function returns the positive (absolute) value of a number.


number (Required)float/intthe number parameter accepts any number the function will return a int or float depending on the number passed through this parameter.

Few Technical Details

Return ValuePositive (absolute) number
Return typeInt / Float
PHP Version4+

Converting Negative Numbers To Positive Numbers

For converting a negative number to a positive number the you just need to pass a number to the abs() function. You can pass any float / int to this php function.

Here is an example of how you can do it –

   $num = -1.5 ;
   $pos_num = abs($num);

   echo $pos_num ;

I hope you understood and implemented the function properly. In case if you didn’t understand anything or you need some help related to this function feel free to ask me in the comments section below.

Few other amazing php tutorials for you –