I need to solve the issue related to the double representation. For example, I have the following set of values:
id: 1 val: 8.11 floor: 8.109999 ceil: 8.11
id: 2 val: 8.31 floor: 8.31 ceil: 8.310001
id: 3 val: 8.27 floor: 8.27 ceil: 8.27
id: 4 val: 12.469999999999999 floor: 12.469999 ceil: 12.47
id: 5 val: 1.9700000000000002 floor: 1.97 ceil: 1.970001
where
val = value coming from a certain operation,
value_ceil = Math.ceil(value * 1000000)/1000000;
value_floor = Math.floor(value * 1000000)/1000000;
As you can see, there are different "scenarios" which fit my needs:
* when the initial value is "ready" (= as expected):
- all of them give me the desired output (id 3)
- val and floor give me the desired output (id 2)
- val and ceil give me the desired output (id 1)
* when the initial value has to be "adjusted":
- floor provides the desired output (id 5)
- ceil provides the desired output (id 4 )
Is there a unique way to manage all the cases obtaining the desired double value?
Thanks
EDIT: Could
Math.round(value * 1000000.0)/1000000.0
solve the issue?