I get a very strange problem. I get two different outputs from the same operation. The problem is described here.
double num = 2.0170818E7;
int dp = 4;
String s = (Math.round(num * Math.pow(10, dp)) / (int) Math.pow(10, dp)) + "";
When I run the above code set in Android 5.0+, I get the output as:
The correct conclusion:
20170818
When I run the above code set under Android 5.0 (I tried with version 4.4.2), I get the output as:
Invalid output:
20172835
Correct conclusion: 20170818or expected conclusion. Why am I getting this strange problem?
source
share