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(2340);

absval(-2340);

absval(4.34560);

absval(-4.34560);

absval(-1.3E+190);

absval(1.3E+190);

absval(M_PI0);

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

absval(2341);

absval(-2341);

absval(4.34561);

absval(-4.34561);

absval(-1.3E+191);

absval(1.3E+191);

absval(M_PI1);

?>