如何做10.1 + 3.4? (但結果是13) 結果需要是:13.5。 我該如何解決它?如何做10.1 + 3.4? (但結果是13)
代碼:
[appdelegate.object.moneyW replaceObjectAtIndex:[row intValue] withObject:[NSString stringWithFormat:@"%d", [mangerMonetMuchS intValue]+[alertNumberB.text intValue]]];
如何做10.1 + 3.4? (但結果是13) 結果需要是:13.5。 我該如何解決它?如何做10.1 + 3.4? (但結果是13)
代碼:
[appdelegate.object.moneyW replaceObjectAtIndex:[row intValue] withObject:[NSString stringWithFormat:@"%d", [mangerMonetMuchS intValue]+[alertNumberB.text intValue]]];
不是使用int值,而是使用float值。
[appdelegate.object.moneyW replaceObjectAtIndex:[row intValue] withObject:[NSString stringWithFormat:@"%d", [mangerMonetMuchS floatValue]+[alertNumberB.text floatValue]]];
PS:你爲什麼使用NSNumber?
感謝它的工作,但它必須是@「%f」, 而當我這樣做時,我看到很多這樣的零:13.500000。 – gal050 2012-02-25 10:28:17
嗯...相反,如何使用%@並帶走floatValue方法。 – TheAmateurProgrammer 2012-02-25 10:47:24
我正在做%@但它不起作用。 – gal050 2012-02-25 10:55:13
你的問題目前太模糊了,特別是因爲你沒有顯示任何代碼。請閱讀http://tinyurl.com/so-hints – 2012-02-25 08:59:19
你可以添加一些代碼來清楚你的問題嗎? – sch 2012-02-25 09:04:35
它給你13還是你想讓它給你13? – Darren 2012-02-25 09:23:35