• Das kreative Thema des Monats Oktober wird vor allem diejenigen unter Euch besonders ansprechen, denen Do-it-yourself quasi im Blut liegt. Zeigt uns Eure Improvisationskünste oder fotografiert, was andere Leute sich so im Alltag zusammengestrickt haben. --> Zum Mitmachen bitte hier klicken

Double/Float-Ausgabe

Nighthawk

Linsenhofener Sämling
Registriert
16.12.06
Beiträge
2.558
Ich möchte eine Double- bzw. Float-Zahl ausgeben. Dazu steck ich sie in einen NSString mit
Code:
[stringWithFormat:@"%lf", dieVariable]

Leider hängt er dann Nullen hinter's Komma, obwohl gar keine Nachkommastellen vorhanden sind.Kann ich das irgendwie umgehen.
 
RTFM!
String Programming Guide for Cocoa schrieb:
The NSString class supports the format characters defined for the ANSI C function printf(), plus %@ for any object
man printf schrieb:
An optional period, `.', followed by an optional digit string giving a precision which specifies the number of digits to appear after the decimal point, for e and f formats, or the maximum number of characters to be printed from a string;
Also:
Code:
%.0lf
 
  • Like
Reaktionen: Nighthawk