2012-11-29 76 views
-5

林分2個值與此代碼:將小數點後移2位?

float final = cw/q ; 
    label.text = [NSString stringWithFormat:@"%g", final]; 

此代碼工作完美,但我該如何移動小數點兩個空間的權利。

像這樣: 0.500000 50.000或僅有50

感謝

+0

它很簡單,只要乘以100 :) –

+2

你嘗試'label.text = [的NSString stringWithFormat:@ 「%G」,最終* 100];'? – ppeterka

+0

你在尋找這個http://stackoverflow.com/questions/560517/make-a-float-only-show-two-decimal-places –

回答

3

呃,怎麼樣轉換爲文本之前乘以100?

float final = (cw/q) * 100.0; 
+0

謝謝,我覺得自己像一個白癡。 –

相關問題