我收到来自用户输入一个的NSString是来找我的是这样的:$ 10,000.00转换的NSString浮动
我有剥去$关闭的方法:
- (NSString*) stripDollarSign : (NSString*) stringToStrip {
//check to see if the number is already formatted correctly
NSRange dollarSignCheck = [stringToStrip rangeOfString:@"$"];
//only strip it if it has the $
if (dollarSignCheck.location != NSNotFound) {
NSString* cleanedString = [stringToStrip substringWithRange:NSMakeRange(1, stringToStrip.length-1)];
return cleanedString;
}
return 0;
}
,我的回报10,000.00(仍然是NSString)。
如果我这样做与清洗结果:
float value = [inputString floatValue]
我得到这个:
10.00
如果我尝试将其转换为NSDecimal我得到10
[[NSDecimalNumber alloc] initWithString:inputString];
我需要做些什么来转换这个,所以我得到10,000.00?
'NSNumberFormatter':http://developer.apple.com/library/ios/#documentation/cocoa/reference/foundation/Classes/NSNumberFormatter_Class/Reference/Reference.html – 2013-05-13 15:14:44