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

How to convert negative numbers to positive numbers in php?

青灯夜游
Release: 2023-02-28 20:34:02
Original
7945 people have browsed it

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);
Copy after login

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));
?>
Copy after login

Output:

6.7
6.7
3
3
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template