I have a question about java floating point arithmetic and its accuracy. I did my research here and through google and found some solutions, but I had difficulty implementing them in my design. Therefore, in Java, I use the BigDecimal class to accurately calculate my calculations. Please note that the variables are double, and when performing calculations, the values ββcan have an accuracy of up to 8 decimal places on the right. The result (accuracy) for the display is known, and this is what I will store as the current value. In addition, all values ββare delivered dynamically (using the method). The argument passed must be currentValue + step size.
public void newValue(float value) {
}
Now it works with some values, but not with all. Especially when I was fiddling with step size. Therefore, if step = 0.1, that was good. If I made it 0.005, I would get an AirthmeticException - the non-ending decimal extension in the step in which
totalStepsBD = totalStepsBD.divide(stepBD, mcI);
When the step variable is set to .005, after creating BigDeciaml (stepBD), it leaves .0049999999 ... Not sure if this helps, but if you have any ideas, let me know. Thanks.
source share