abs


php128 apg

RETURNS the ABSOLUTE value of number.

Compatible with LOCALE, only, until PHP 7.4.XX.





This function returns the absolut value of $num.

If $num is a FLOAT the return is also a FLOAT.

If $num is an INTEGER, the return is an INTEGER.

As FLOAT usually has a bigger value range than INTEGER.



<?php

int
|float abs ( int|float $num )


where,

$num = The numeric value to be processed

?>
 

$num


The number to process.

As off PHP 8.0.0 no longer accepts internal objects which support numeric conversion.



  1 EXERCISE   

<?php

function absval($val01, $loc01)
{
    
if(
$loc01 == 0)
{
    
setlocale(LC_ALL, "en_US", "en-US", "american", 
                 
"american english", "american-english", 
                 
"english-american", "english-us", 
                 
"english-usa", "enu", "us", "usa");
    
    echo 
abs($val01) . ' = | ' . $val01 . ' |<br><br>';
}
else
{
    
setlocale(LC_ALL, "pt_BR.utf-8", "pt-BR.utf-8", 
                                     
"portuguese-brazil", "ptb");
    
    echo 
abs($val01) . ' = | ' . $val01 . ' |<br><br>';
}

}

echo 
'LOCALE = en_US<br><br>';

absval(234, 0);

absval(-234, 0);

absval(4.3456, 0);

absval(-4.3456, 0);

absval(-1.3E+19, 0);

absval(1.3E+19, 0);

absval(M_PI, 0);

echo 
'LOCALE = pt_BR<br><br>';

absval(234, 1);

absval(-234, 1);

absval(4.3456, 1);

absval(-4.3456, 1);

absval(-1.3E+19, 1);

absval(1.3E+19, 1);

absval(M_PI, 1);

?>