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 07-10-2009, 01:57 PM   #1 (permalink)
Registered Member
 
Glnn's Avatar
 
Join Date: Jun 2009
Location: Netherlands
Posts: 31
Default double -> string formatting

I'm having trouble formatting a double to a string..

This is the code is use..

Code:
secondLabel.text = [NSString stringWithFormat:@"%i.%i", second, millisecond];

NSString *convert = [NSString stringWithFormat:@"%i.%i", second, millisecond];
kilometers = [convert doubleValue];
kilometers = kilometers * 2.9;
meterLabel.text = [NSString stringWithFormat:@"%d", kilometers];
and this is the result..



Anybody?
Glnn is offline   Reply With Quote
Old 07-10-2009, 04:43 PM   #2 (permalink)
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: żLa Islas Hermosas?
Posts: 2,178
Default

Quote:
Originally Posted by Glnn View Post
I'm having trouble formatting a double to a string..

This is the code is use..

Code:
secondLabel.text = [NSString stringWithFormat:@"%i.%i", second, millisecond];

NSString *convert = [NSString stringWithFormat:@"%i.%i", second, millisecond];
kilometers = [convert doubleValue];
kilometers = kilometers * 2.9;
meterLabel.text = [NSString stringWithFormat:@"%d", kilometers];
and this is the result..



Anybody?
Couple things: (1) it's not clear from your post which snippet of code is responsible for the image that you posted, (2) "%d" is for integers and shouldn't result in a number with a decimal point, and (3) you haven't specified exactly what output you're looking to achieve.

Here's a link to some Apple documentation on string formatters: String Programming Guide for Cocoa: String Format Specifiers.
__________________
~~ Word Flurry ~~ App Store / Website / Facebook
Kalimba is offline   Reply With Quote
Old 07-10-2009, 04:50 PM   #3 (permalink)
Registered Member
 
Glnn's Avatar
 
Join Date: Jun 2009
Location: Netherlands
Posts: 31
Default

You're right..
The way I'm asking the question isn't really good..

The link you posted, it helped me..
So thank you
Glnn 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
» Online Users: 688
22 members and 666 guests
ags9, armmzz, biskwit, chiataytuday, CS@UCSB, DanicaJackson, Dashcab, dschivas, elhanche, hearther, laxus02, litium, lukeirvin, mer10, mineva2kul, mistergreen2011, nguyenhieu129, Oral B, Profile, Rudy, skrew88, wingliling
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,767
Threads: 89,201
Posts: 380,573
Top Poster: BrianSlick (7,129)
Welcome to our newest member, litium
Powered by vBadvanced CMPS v3.1.0

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