小编Gil*_*ert的帖子

Objective C将int转换为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);
Run Code Online (Sandbox Code Playgroud)

非常坦率的.Rawtime是一个值为1200的int.输出如下:

0:0:1

0x1.3eaf003d9573p-962:0x1.7bd2003d3ebp-981:-0x1.26197p-698
Run Code Online (Sandbox Code Playgroud)

为什么将int转换为字符串会产生如此狂野的数字呢?我尝试过使用%i和%u,但没有区别.怎么了?

string iphone int objective-c

9
推荐指数
2
解决办法
3万
查看次数

标签 统计

int ×1

iphone ×1

objective-c ×1

string ×1