2012-02-25 58 views
-5

如何做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]]]; 
+1

你的問題目前太模糊了,特別是因爲你沒有顯示任何代碼。請閱讀http://tinyurl.com/so-hints – 2012-02-25 08:59:19

+1

你可以添加一些代碼來清楚你的問題嗎? – sch 2012-02-25 09:04:35

+0

它給你13還是你想讓它給你13? – Darren 2012-02-25 09:23:35

回答

1

你們是不是要賦值給一個Int?因爲如果是這樣,13.5將被截斷爲13.確保所有變量都是浮點數,而不是整數。

+0

如何解決它? – gal050 2012-02-25 10:03:53

1

不是使用int值,而是使用float值。

[appdelegate.object.moneyW replaceObjectAtIndex:[row intValue] withObject:[NSString stringWithFormat:@"%d", [mangerMonetMuchS floatValue]+[alertNumberB.text floatValue]]];

PS:你爲什麼使用NSNumber?

+0

感謝它的工作,但它必須是@「%f」, 而當我這樣做時,我看到很多這樣的零:13.500000。 – gal050 2012-02-25 10:28:17

+0

嗯...相反,如何使用%@並帶走floatValue方法。 – TheAmateurProgrammer 2012-02-25 10:47:24

+0

我正在做%@但它不起作用。 – gal050 2012-02-25 10:55:13

相關問題