rkb
rkb

Reputation: 11231

How to format a double Value upto 2 decimal places in iPhone

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

Upvotes: 2

Views: 5661

Answers (3)

Erik Reynolds
Erik Reynolds

Reputation:

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

Upvotes: 0

Terry Wilcox
Terry Wilcox

Reputation: 9040

See NSNumberFormatter. It formats numbers.

Upvotes: 1

Ben Gottlieb
Ben Gottlieb

Reputation: 85532

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

Upvotes: 7

Related Questions