2

I am extracting double data from sqlite3 database. But I want to display it only upto two decimal places. So how to truncate it.

rkb
  • 10,933
  • 22
  • 76
  • 103

3 Answers3

7

Use sprintf formatting with NSString: [NSString stringWithFormat: @"%.2f", myValue];

Ben Gottlieb
  • 85,404
  • 22
  • 176
  • 172
1

See NSNumberFormatter. It formats numbers.

Terry Wilcox
  • 9,010
  • 1
  • 34
  • 36
0

Ah, Ben beat me to it! You might also find this http://developer.apple.com/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html useful.