Home > Article > Backend Development > How to convert negative numbers to positive numbers in php?
How to convert negative numbers to positive numbers in php?
In PHP, you can use the abs() function to convert negative numbers into positive numbers.
#abs() function returns the absolute value of a number.
Syntax
abs(number);
Parameters: number Required. Specify a number. If the type of the number is floating point, the returned type is also floating point, otherwise it is returned as an integer.
Return value: The absolute value of number.
Return type: Float / Integer
Example:
<?php echo(abs(6.7) . "<br>"); echo(abs(-6.7) . "<br>"); echo(abs(-3) . "<br>"); echo(abs(3)); ?>
Output:
6.7 6.7 3 3
For more related knowledge, please pay attention to PHP中文网! !
The above is the detailed content of How to convert negative numbers to positive numbers in php?. For more information, please follow other related articles on the PHP Chinese website!