Let’s try this :
float test = 3.56;
float roundedVal = round(test * 10.0f) / 10.0f;
NSLog (@"%f", roundedVal);
Why does tthe NSLog shows 3.600000, and the debugger 3.5999999 ?
What is the correct value I can count on ?
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.
A
floatis not very precise and you can’t expect them to be displayed accurately from one “view” to the next depending on a variety of factors. Read What Every Computer Scientist Should Know About Floating-Point Arithmetic.Boils down to this: use
doubleif you really want precision.