When working with numbers, I encountered a discrepancy in the results obtained from calculating and rounding. The value for today is 336887, and for yesterday it is 336582. I faced a similar issue with a different field, but after updating the Java code, the difference disappeared.
Snippet of Javascript Code:
document.getElementById("txt1").value = ((today - yesterday) / 10000).toFixed(3);
Snippet of Android Code:
public Double RoundDouble(Double num, Integer places)
{
Double temp = Math.pow(10.0, places);
num = num * temp;
Math.round(num);
num = num / temp;
return num;
}
Double total = RoundDouble((today - yesterday) / 10000,3);
txt1.setText(df.format(total ));
The calculated results differ where the Javascript code returns .031, and the Android code returns .030. The calculation before rounding gives .0305. The reason behind this discrepancy is unclear, especially when another field had no issue rounding .0295 to .030 accurately.