我有一個標籤,我們稱之爲currencyFormattedLabel,它的價值是在另一種方法中作爲貨幣格式化(使用currencyFormatter)。如何獲取貨幣格式標籤的floatValue金額?
現在,我想使用該標籤中的等效數字。但是,當我去獲取數字時,我只能得到0.00的值。
也許這將有助於解釋:
float x = [currencyFormattedLabel.text floatValue];
NSLog(@"x = %.2f", x);
所以,如果currencyFormattedLabel爲$ 2.00,此方法始終結束返回:X = 0.00 我要的是它返回X = 2.00。
有沒有辦法讓我currencyFormattedLabel並獲得它的數字值?
感謝您的幫助!
currencyFormattedLabel.text返回什麼值?這是你期望的嗎? – bneely 2012-02-10 19:05:54
提示:NSLog(@「text =%@」,currencyFormattedLabel.text); – bneely 2012-02-10 19:06:20
另外,[不要使用浮動金錢](http://stackoverflow.com/questions/6333711/objective-c-issue-with-rounding-float/6334471#6334471)。你真的應該得到一個代表美分的整數值。 – 2012-02-10 19:29:29