Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

modifying least significant bits in double (Java and C++)

Tags:

java

c++

double

How to set to zero N least significant bits of a double in Java and C++?
In my computations, the "...002" in 1699.3000000000002, is caused by numerical error, so I would like to eliminate it.

like image 376
Serg Avatar asked Mar 12 '26 10:03

Serg


1 Answers

I'd guess that you are actually doing currency calculations. In which case using a binary data type like double is probably the root cause of your problems. Switch to a decimal type and you should be able to side-step such issues.

like image 90
David Heffernan Avatar answered Mar 13 '26 23:03

David Heffernan