Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-07-2009, 08:01 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2008
Age: 67
Posts: 112
Default 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.
imntacrook is offline   Reply With Quote
Old 02-07-2009, 08:04 PM   #2 (permalink)
Registered Member
 
tkilmer's Avatar
 
Join Date: May 2008
Posts: 583
Default

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.
tkilmer is offline   Reply With Quote
Old 02-07-2009, 08:18 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2008
Age: 67
Posts: 112
Default

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.
imntacrook is offline   Reply With Quote
Old 02-07-2009, 08:29 PM   #4 (permalink)
Registered Member
 
tkilmer's Avatar
 
Join Date: May 2008
Posts: 583
Default

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
tkilmer is offline   Reply With Quote
Old 02-07-2009, 08:38 PM   #5 (permalink)
Registered Member
 
Join Date: Sep 2008
Age: 67
Posts: 112
Default

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
imntacrook is offline   Reply With Quote
Old 02-07-2009, 08:40 PM   #6 (permalink)
Registered Member
 
tkilmer's Avatar
 
Join Date: May 2008
Posts: 583
Default

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.
tkilmer is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 158,475
Threads: 89,090
Posts: 380,122
Top Poster: BrianSlick (7,091)
Welcome to our newest member, drg4cen
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:57 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0