Suppose n is a Double type variable .
double right=n-(Math.ceil(n)-1);
//Here I am trying to get the right part of the number.
Now if n=1234.78
then right=0.7799999999999727
why not .78
?
and when
n=1234.89
then right=0.8900000000001
why not 89
? and why not 9999
... here instead of 000000
....?
Now suppose I want to find the sum of digits in right..Like in my example for 1234.89 its 8+9=17 or 1234.781 its 7+8+1-16. So then ?what should I do?
But I can't do it using floating point arithmatic?Like
double temp=0.0;
while(right>0)
{
right=rigth*10;
temp=Math.floor(right);
right=right-temp;
suml+=temp;
}
in kind of a way I mentioned above? I am new to java. please explain my problem. It would be a great help for me. Thank you.