Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.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, 12:57 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Netherlands
Posts: 27
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, 03:43 PM   #2 (permalink)
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: ¿La Islas Hermosas?
Posts: 1,426
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.
__________________
piña para la niña interactive
Kalimba is online now   Reply With Quote
Old 07-10-2009, 03:50 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Netherlands
Posts: 27
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


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,208
Threads: 38,991
Posts: 171,023
Top Poster: smasher (2,569)
Welcome to our newest member, JDBurgie
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:11 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0