-2

Possible Duplicate:
Limit a double to two decimal places

I want to display numbers in specific format in Objective C. Here, I just want to show the numbers with two precision.

Suppose I have numbers like 25.5;

Then I want show number as given below.

25.5 => 25.50

Community
  • 1
  • 1
kasun tharanga
  • 87
  • 1
  • 1
  • 4

2 Answers2

10

Replace to

taxLbl.text = [NSString stringWithFormat:@"%.2f", [sum doubleValue]];
Hector
  • 3,909
  • 2
  • 30
  • 46
  • //To Do: 2 decimal places NSNumber *sum = [NSNumber numberWithFloat:([refreshOrderResponse.TaxPrice doubleValue] + [refreshOrderResponse.ServiceChargePrice doubleValue])]; taxLbl.text = [NSString stringWithFormat:@"%@", [sum stringValue]]; – kasun tharanga Mar 01 '12 at 05:53
  • 1
    try this taxLbl.text = [NSString stringWithFormat:@"%.2f", [sum doubleValue]]; – Hector Mar 01 '12 at 06:01
  • @Hector +1 for your kind support. – Kamar Shad Mar 01 '12 at 06:55
1

You probably want to take a look at the NSNumberFormatter class reference.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469