2013-08-17 25 views
-3

我想在顯示的數字後設置2個小數位。在iOS的標籤上放置2位小數

.H

- (IBAction)CalculateSpeed:(id)sender; { 
int iSliderValue = [_sliKilometre value]; 
[_lblCelsiusValue setText: [NSString stringWithFormat:@"%d", iSliderValue]]; 
int iFahrenheit = iSliderValue * 1*0.621371192; 
[_lblFahrenheitValue setText: [NSString stringWithFormat:@"%d.2f", iFahrenheit]]; }  
+4

這與Xcode無關。除此之外,使用'float','%.2f',並閱讀好初學者的C書(這是非常基本的)。 [從這裏開始](http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list)。 – 2013-08-17 10:08:58

+5

這個問題似乎是脫離主題,因爲它太本地化了。 – 2013-08-17 10:09:53

回答

2

使用此:

NSString* twoDecimalPointString = [NSString stringWithFormat:@"%.02f", floatNumber]; 

%.02f這是非常重要的。