我希望你能幫助我解決這個「小問題」。我想將一個字符串轉換爲double/float。要加倍的字符串
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];
但都沒有成功。
結帳這個問題:http://stackoverflow.com/questions/169925/how-to-do-string-conversions-in-objective- c ...您需要爲用戶在其設置中設置的語言環境設置一個「NSNumberFormatter」,並使用它來獲取字符串中的信息。 – klaustopher