programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Liutauras Vilda
• Campbell Ritchie
• Tim Cooke
• Bear Bibeault
• Devaka Cooray
Sheriffs:
• Jeanne Boyarsky
• Knute Snortum
• Junilu Lacar
Saloon Keepers:
• Tim Moores
• Ganesh Patekar
• Stephan van Hulst
• Pete Letkeman
• Carey Brown
Bartenders:
• Tim Holloway
• Ron McLeod
• Vijitha Kumara

# BigDecimal abs not return exactly value

Ranch Foreman
Posts: 111
1
I would like to remove the negative sign value

But I get 0.2059999999999999886757251488234032876789569854736328125 instead of 0.206. I though abs will returns a BigDecimal whose value is the absolute value of this BigDecimal, no ?
Can someone explain ?

Bartender
Posts: 2180
46
• 1
You can find the answer is in the javadoc of the constructor.
It is not a problem with the abs() method. It is a problem with the instance of BigDecimal that you are creating.

Saloon Keeper
Posts: 9248
177
To further clarify what Paweł wrote, the value you are using to create the BigDecimal instance with is not actually -0.206, but the closest value that can be represented by the double datatype.

Paweł Baczyński
Bartender
Posts: 2180
46

Stephan van Hulst wrote:To further clarify what Paweł wrote, the value you are using to create the BigDecimal instance with is not actually -0.206, but the closest value that can be represented by the double datatype.

And this value is exactly -0.2059999999999999886757251488234032876789569854736328125.

Marshal
Posts: 60155
188
• 1

Paweł Baczyński wrote:You can find the answer is in the javadoc of the constructor. . . . .

You will also find the solution to correct your problem. Alternatively, try its valueOf() method.

Randy Tong
Ranch Foreman
Posts: 111
1
Thanks all

Campbell Ritchie
Marshal
Posts: 60155
188
• 1
That's a pleasure