【发布时间】:2016-08-16 09:29:55
【问题描述】:
我试图从算盘游戏中获得十亿和百万值,在 iphone 5s 和 iphone 6 上它给我正确的值,但在 iphone 4s 和 iphone 5 上它给我负格式的值,我尝试了数据类型 long long , long 但仍然没有给我正确的值 这是我的代码,它在 iphone 5s 和 6 上运行良好,但给出警告并给出减号格式的数字,任何人都可以帮助我吗 这是我的代码图片
NSString *digitLabelText;
if([self digit] == 0)
{
digitLabelText= [NSString stringWithFormat:@"%ld", (long)[self digit]];
}
else
{
if([self placeValue] == ONE || [self placeValue] == TEN ||
[self placeValue] == ONE_HUNDRED || [self placeValue] == ONE_THOUSAND)
{
digitLabelText= [NSString stringWithFormat:@"%ld", (long)[self digit]];
}
else if([self placeValue] == TEN_THOUSAND)
{
digitLabelText= [NSString stringWithFormat:@"%ld,000",(long)[self digit]/ONE_THOUSAND];
}
else if([self placeValue] == HUNDRED_THOUSAND)
{
digitLabelText= [NSString stringWithFormat:@"%ld,000", (long)[self digit]/ONE_THOUSAND];
}
else if([self placeValue] == ONE_MILLION)
{
digitLabelText= [NSString stringWithFormat:@"%ld mil", (long)[self digit]/ONE_MILLION];
}
else if([self placeValue] == TEN_MILLION)
{
digitLabelText= [NSString stringWithFormat:@"%ld mil", (long)[self digit]/ONE_MILLION];
}
else if([self placeValue] == HUNDRED_MILLION)
{
digitLabelText= [NSString stringWithFormat:@"%ld mil", (long)[self digit]/ONE_MILLION];
}
else if([self placeValue] == ONE_BILLION)
{
//issue come from this in iphone 4s ,5 digitLabelText= [NSString stringWithFormat:@"%ld bil", (long)[self digit]/ONE_BILLION];
}
else if([self placeValue] == TEN_BILLION)
{
digitLabelText= [NSString stringWithFormat:@"%ld bil", (long)[self digit]/ONE_BILLION];///ONE_BILLION];
}
else if([self placeValue] == HUNDRED_BILLION)
{
digitLabelText= [NSString stringWithFormat:@"%ld bil", (long)[self digit]/ONE_BILLION];///ONE_BILLION];
}
else if([self placeValue] == ONE_TRILLION)
{
digitLabelText= [NSString stringWithFormat:@"%lld tril", (long)[self digit]/ONE_TRILLION];///ONE_TRILLION];
}
}
digitLabel.text = digitLabelText;
【问题讨论】:
-
请在 cmets 中包含您的代码。外部链接可能会中断。
-
查找“
NSInteger最大值”以了解原因。 -
另外,这似乎是一个 XY 问题。您问题的实际解决方案似乎是对数。
标签: ios objective-c