ho il seguente codice che ha lo scopo di convertire millisecondi in ore, minuti e secondi:Objective C Convert int a NSString (iPhone)
int hours = floor(rawtime/3600000);
int mins = floor((rawtime % 3600000)/(1000 * 60));
int secs = floor(((rawtime % 3600000) % (1000 * 60))/1000);
NSLog(@"%d:%d:%d", hours, mins, secs);
NSString *hoursStr = [NSString stringWithFormat:@"%d", hours];
NSString *minsStr = [NSString stringWithFormat:@"%d", mins];
NSString *secsStr = [NSString stringWithFormat:@"%d", secs];
NSLog(@"%a:%a:%a", hoursStr, minsStr, secsStr);
abbastanza semplice. Rawtime è un int con valore di 1200. L'uscita è come questo:
0:0:1
0x1.3eaf003d9573p-962:0x1.7bd2003d3ebp-981:-0x1.26197p-698
Perché è che la conversione dei interi in stringhe dà tali numeri selvatici? Ho provato a utilizzare% i e% u e non hanno fatto alcuna differenza. Che cosa sta succedendo?
Duplicato (?) Di [come convertire da int a stringa in iphone] (http://stackoverflow.com/questions/1372715/how-to-convert-from-int-to-string-in-iphone) –