在我的应用程序中,如果NSString包含负整数,我想要显示0
。我试图将NSString转换为signed int,但是我的NSString以signed int转换代码始终返回0
值。如何将带负整数的NSString转换为负整数
如:我想
@"-0.02"
转化为-0.02 int
。但我的代码总是返回0
而不是原始值。
我试图与下面的代码:
(signed)[@"-0.02" intValue]
//返回0[[NSNumberFormatter new] numberFromString:timespent]
//返回的NSNumber与-0.02值但同时做< 0
比较,我转换成NSNumber
作为signedIntValue
//(signed)[[[NSNumberFormatter new] numberFromString:timespent] intValue]
但它返回0
任何人都知道怎么做,在iOS版 - Objective-C的?
float numFloat = [@“ - 0.02”floatValue]; //返回-0.02。 – GeneCode
你应该尝试使用这个'NSString * value = @“ - 123”; intValueOfString = [值IntergerValue];'。 而不是** intValue ** use ** intergerValue ** –
您应该阅读您的语言中的“integer”(int)的翻译,或者了解它的数学含义。 – Larme