Okay this program is supposed to take any integer entered by a user, then strip off the individual digits and sum them up. I just can't work out this last error I keep getting. Any idea how to fix it? Heres the code and the error message...
C:\My Documents\Homework 6\IntSum2.java:32: possible loss of precision found : double required: int num = (InputNum / Math.pow(10, count) % 10); ^ 1 error Not sure why its telling me loss of precision, I think the equation is okay the way it is. I didnt start getting the error untill I put Math.pow into the equation.
Joined: Oct 10, 2003
hiii.. If you go through JavaDocs then you will find that Math.Pow() return a double and in this case you need to are storing the value in an int datatype. tgus according to Java when u r storing a bigger datatype into a smaller in which there is possibility of loss of precision then you need to explicitly type cast it.. so u can do this in any of the following manner and your error will be gone..
i hope i have answered your question... if still in doubt please get back Thanks Amit
****************************<br />In 24 hrs Earth rotates once on its Axis.