Home  >  Article  >  Database  >  How to convert negative numbers to positive numbers in mysql

How to convert negative numbers to positive numbers in mysql

coldplay.xixi
coldplay.xixiOriginal
2020-10-27 15:15:205347browse

Mysql method to convert negative numbers to positive numbers: use the function [abs();] to convert negative numbers to positive numbers, the code is [mysql> select abs(3-5);abs(3-5);row in set (0.00 sec)].

How to convert negative numbers to positive numbers in mysql

Mysql method to convert negative numbers to positive numbers:

1, MySQL

Function: abs ()

abs(); //Convert negative numbers to positive numbers

as follows:

mysql> select abs(3-5);
+----------+
| abs(3-5) |
+----------+
|        2 |
+----------+
row in set (0.00 sec)

2, PHP

Function: abs()

<?php
$test = -1;
echo $test;
$test = abs($test);
echo $test;

Output:

-1

1

##More related free learning recommendations: mysql tutorial(Video)

The above is the detailed content of How to convert negative numbers to positive numbers in mysql. 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