In javascript, you can use the abs() function to convert a negative number into a positive number by taking the absolute value of a negative number; the syntax format is "Math.abs(x)", and the parameter x is the negative value that needs to be converted to a positive number. , for example "Math.abs(-7.25)".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
js absolute value (convert negative value to positive)
The absolute value operation of junior high school algebra, syntax:
| -1000 | = 1000;
js code is as follows:
var t = -1000; Math.abs(t);
Output:
[Recommended learning: js basic tutorial]
Introduction to related functions
#abs() method can return the absolute value of a number. The syntax is as follows:
Math.abs(x)
Parameter value:
Type | Description |
---|---|
Number# The absolute value of | ##x. Returns NaN if x is not a number, or 0 if x is null.
Description | |
---|---|
x. Returns NaN if x is not a number, or 0 if x is null. |
Programming Video! !
The above is the detailed content of How to convert negative numbers to positive in javascript. For more information, please follow other related articles on the PHP Chinese website!