Home  >  Article  >  Backend Development  >  How to convert negative numbers to positive numbers in php?

How to convert negative numbers to positive numbers in php?

青灯夜游
青灯夜游Original
2020-04-25 17:41:287900browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn