When I do the following, the output is an integer value:
double myvar = fabs(-5.01);
NSLog(@"%.f", myvar);
Should it be 5.01?
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.
The
.(with no number after it) in"%.f"means format with a precision of 0 (which for floats, means round to the nearest integer). You probably just want “%f”See http://www.cplusplus.com/reference/clibrary/cstdio/printf/ for a description of the format specifiers (I gather the
NSLogformat specifiers are a superset of theprintfones)