Possible Duplicate:
Java : how do I get the part after the decimal point?
In my previous post I didn't give proper explanation. This is my exact scenario.
I have a double
variable d = 1.15
.
I want the number after the decimal point, i.e. "15".
What is best way to achieve this in Java?
I have tried like this:
Double d = 1.15;
String str = d.toString();
int len = str.substring(str.indexOf(".")).length() - 1;
int i= (int) (d * (long)Math.pow(10,len) % (long)Math.pow(10,len));
But I didn't get the proper answer because when I convert d.toString()
the answer is 14.999999999999986
.