-4

I want to have 2 decimal places set after displayed number.

.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
    This is not related to Xcode by any means. Apart from that, use `float`, `%.2f`, and read good beginners' C book (this is very basic). [Start here](http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list). –  Aug 17 '13 at 10:08
  • 5
    This question appears to be off-topic because it is too localized. –  Aug 17 '13 at 10:09

1 Answers1

2

Use this:

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

It's %.02f that's important.

JPetric
  • 3,838
  • 28
  • 26