Math.abs(value) Last updated: 16. May 2026
Turns any number into a positive number. If positive no change, if negative the value is multiplied by -1.
See also: Math.ceil Math.floor Math.round
Parameters
| Name | Type | Description |
|---|---|---|
| value | number | Value to make positive. |
Returns
A positive number
Example
Code example (#JS)
#JS is mixed HTML (or other text file) with inline JavaScript with # starting and ending each inline statement.// expected output: 5
#Math.abs(-5)#
// expected output: 5
#Math.abs(5)#
// expected output: 3.14
#Math.abs(-3.14)# Output
The #JS code above produces the output shown below:// expected output: 5
5
// expected output: 5
5
// expected output: 3.14
3.14 Code example (JS)
JS is normal JavaScript either running in the browser or on the Docly™ server.write(Math.abs(-5));
write("\n");
write(Math.abs(5));
write("\n");
write(Math.abs(-3.14));
/* Expected output:
5
5
3.14
*/ Output
The JS code above produces the output shown below:5
5
3.14