【发布时间】:2011-09-26 12:38:50
【问题描述】:
我希望你能帮我解决这个“小”问题。我想将字符串转换为双精度/浮点数。
NSString *stringValue = @"1235";
priceLabel.text = [NSString stringWithFormat:@"%d",[stringValue doubleValue]/(double)100.00];
我希望这可以将 priceLabel 设置为 12,35,但我得到了一些奇怪的长字符串,对我来说毫无意义。
我试过了:
priceLabel.text = [NSString stringWithFormat:@"%d",[stringValue intValue]/(double)100.00];
priceLabel.text = [NSString stringWithFormat:@"%d",[stringValue doubleValue]/100];
但都没有成功。
【问题讨论】:
-
检查这个问题:stackoverflow.com/questions/169925/… ...您需要为用户在其设置中设置的语言环境设置
NSNumberFormatter,并使用它从字符串中获取信息。
标签: iphone objective-c xcode double