I’m doing what seems like simple math in an android app, however I keep getting massive rounding errors. For example.
Float.toString(0.4*0.4*12.5);
I would expect to get 2 as the result of the above equation. However I get 2.0000002
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
So I ended up making two functions, one to round Doubles and one for Floats. Seems like a PITA, but other then being limited to a preset level of precision (which I’ll look at making a app setting) it does work.