The example below show you how to get the absolute value of a number. To get the absolute value or the abs value of a number we use the `Math.abs()`

method call. The `Math.abs()`

method is an overloaded that can accept value in type of `double`

, `float`

, `int`

or `long`

.

```
package org.kodejava.example.math;
public class GetAbsoluteValueExample {
public static void main(String[] args) {
Double value = -10.0D;
double abs1 = Math.abs(value);
System.out.println("Absolute value in double: " + abs1);
float abs2 = Math.abs(value.floatValue());
System.out.println("Absolute value in float : " + abs2);
int abs3 = Math.abs(value.intValue());
System.out.println("Absolute value in int : " + abs3);
long abs4 = Math.abs(value.longValue());
System.out.println("Absolute value in long : " + abs4);
}
}
```

The code snippet above print the following result:

Absolute value in double: 10.0 Absolute value in float : 10.0 Absolute value in int : 10 Absolute value in long : 10

### Wayan Saryada

Founder at Kode Java Org

I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. You can support my works by donating here. Thank you š„³

#### Latest posts by Wayan Saryada (see all)

- How to Install Consolas Font in Mac OS X? - March 29, 2019
- How do I clear the current command line in terminal? - February 14, 2019
- How do I generate random alphanumeric strings? - February 7, 2019