 |
 |
|
 |
07-10-2009, 01:57 PM
|
#1 (permalink)
|
|
Registered Member
Join Date: Jun 2009
Location: Netherlands
Posts: 25
|
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?
|
|
|
07-10-2009, 04:43 PM
|
#2 (permalink)
|
|
Pro. Game Developer
iPhone Dev SDK Supporter
Join Date: Feb 2009
Location: żLa Islas Hermosas?
Posts: 1,261
|
Quote:
Originally Posted by Glnn
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.
__________________
Code free of compiler warnings and errors, and code that won't crash are not mutually exclusive.
How your application performs in the simulator is irrelevant, unless your target audience is people who will run your app only on the simulator.
|
|
|
07-10-2009, 04:50 PM
|
#3 (permalink)
|
|
Registered Member
Join Date: Jun 2009
Location: Netherlands
Posts: 25
|
You're right..
The way I'm asking the question isn't really good..
The link you posted, it helped me..
So thank you
|
|
|
 |
| 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: 514 |
| 43 members and 471 guests |
| bbc z, BostonMerlin, cjamerlan, coolman, CunningCat, dany88, dbarrett, dda, designomatt, embedded, Gamer211, ggalante, gonk, IphoneSdk, jharrah, Kalimba, LemonMeringue, loobian, markbuchanan, MarkC, masc2279, Maximilian, MiniRobinho, montage, mquetel, naomipunkclan, Noise, pashik, pieter78, Pring, saul102, Snappy, soulless, StefanL, Tambourin, the1nz4ne, treazer, TunaNugget, Tuszy, wassupdoc, williamlegate, x2on, ZunePod |
| Most users ever online was 779, 05-11-2009 at 10:55 AM. |
» Stats |
Members: 21,508
Threads: 35,791
Posts: 156,796
Top Poster: smasher (2,449)
|
| Welcome to our newest member, JoelSelwood7 |
|