 |
 |
|
 |
02-07-2009, 08:01 PM
|
#1 (permalink)
|
|
Registered Member
Join Date: Sep 2008
Age: 65
Posts: 112
|
Easy question about formatting
In my .h file I have:
.h
float percent;
My placeholder in the NSTstringWithFormat etc. is %.2f as below:
.m
NSLog([NSString stringWithFormat:@"Percent = %.2f", percent]);
And all I get is zero's after the decimal point in my log.
I've tried many combinations but nothing seems to work.
Thanks in advance.
|
|
|
02-07-2009, 08:04 PM
|
#2 (permalink)
|
|
Registered Member
Join Date: May 2008
Posts: 583
|
A couple things. My personal preference is to always use a double. I know it is double the space, but it is far more precise. Next, you do not have to use the [NSString stringWithFormat] inside NSLog. You can do this:
Code:
NSLog("Percent = %.2f", percent);
Last thing, how do you assign the value of percent. It sounds like the conversion is not properly done. Post your code for how percent is assigned its value.
|
|
|
02-07-2009, 08:18 PM
|
#3 (permalink)
|
|
Registered Member
Join Date: Sep 2008
Age: 65
Posts: 112
|
OK Thanks! I appreciate that, let me try double. And thats a good tip about the NSLog, I didn't realize that. Not to be vague or anything but the percent is going to be (100 / 9 * levelreached) * (45 - hits) / 36; I know that doesn't mean anything to you, but what I'm doing is testing one thing at a time. Just trying to get the output to look correct now.
************ update
double still gives me all zeros after the decimal point.
|
|
|
02-07-2009, 08:29 PM
|
#4 (permalink)
|
|
Registered Member
Join Date: May 2008
Posts: 583
|
Instead of
Code:
(100 / 9 * levelreached) * (45 - hits) / 36
do this
Code:
(100.0 / 9.0 * levelreached) * (45 - hits) / 36.0
This will force it to be a double
|
|
|
02-07-2009, 08:38 PM
|
#5 (permalink)
|
|
Registered Member
Join Date: Sep 2008
Age: 65
Posts: 112
|
Works like a charm thank you sooo much. I think what I need is a good book on syntax and keywords - I'm catching on little by little, and reading Marks and LaMarches, and Hillegass' books but they don't necessarily give the real basics. Thanks again
|
|
|
02-07-2009, 08:40 PM
|
#6 (permalink)
|
|
Registered Member
Join Date: May 2008
Posts: 583
|
This is all basic C. I would get the book "The C Programming Language" by K&R. This will help you a lot with the C side of iphone development.
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 490 |
| 60 members and 430 guests |
| AdyCoder, atsd, AXP, bensj, blackoutq3, BostonMerlin, bravetarget, cakeisalie, CHV, CunningCat, danny8, davek, embedded, Gamer211, ggalante, Gudus, harrytheshark, healthyutech, henmue, iFizzgig, imsatasia, iPhoneDevelopment, IphoneSdk, Jeremy1026, johnnybluejeans, krowczyk, lepetitapps, Link, MacSteve85, markbuchanan, MasterLee, mebarron, MiniRobinho, mlo, nibby, NicolasD, not_too_shabby, P2k, pbcbvba, pokypine, racer_X, raheel, robotcult, SimonK, talakoski, Tambourin, treazer, tturk, Type25, umarmara, vcanic, virvalid, Vivek Nirkhe, Vonswanko, wassupdoc, winklllll, ZunePod |
| Most users ever online was 779, 05-11-2009 at 10:55 AM. |
» Stats |
Members: 21,505
Threads: 35,788
Posts: 156,785
Top Poster: smasher (2,449)
|
| Welcome to our newest member, SimonK |
|