I have this code:
NSString *hString = [NSString stringWithFormat:@"%d", (h * 100)];
HField.text = hString;
H is 0.721.
HField.text now reads:
1073741824
Any ideas why this isn’t giving me 72?
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.
Ah. The problem is that
hseems to be adoubleorfloat. Try this:This should work. You have to use
%ffor floating-point numbers and%dfor integers.Edit
Round will round the float to an integer. You can alternately use
ceil()orfloor()to round up or down, respectively. The(NSInteger)cast is there to make sure it is converted to an integer.