2

Possible Duplicate:
How to add percent sign to NSString

Trying to create some string output using the % symbol with no luck:

[NSString stringWithFormat:@"%@% off entire order.",self.discountPercentage.text]

Example output would hopefully be something like: 25% off entire order.

Instead I get some crazy output: 25377777777776ff entire order.

Is there an escape character I need to use before the %?

Community
  • 1
  • 1
Slee
  • 27,498
  • 52
  • 145
  • 243
  • `NSLog(@"%i%@", 20, [NSString stringWithUTF8String:"% of entire order"]);` also works but is more messy than `%%` – Rad'Val May 29 '11 at 16:26

2 Answers2

5

Use %% to represent the % characters. (See String Programming Guide: String Format Specifiers)

Simon Whitaker
  • 20,506
  • 4
  • 62
  • 79
3

The code for percent sign in NSString format is %%.This is also true for NSLog() and printf() formats.

BDGapps
  • 3,318
  • 10
  • 56
  • 75
  • 1
    It looks like you copy-pasted this answer from a duplicate question: http://stackoverflow.com/questions/739682/how-to-add-percent-sign-to-nsstring/739707#739707 If you _must_ do this, please _at least_ give credit to the other answerer. – jscs May 29 '11 at 19:54
  • No I never saw it. No joke I had it from another app o mine. – BDGapps May 30 '11 at 01:18
  • 1
    Interesting that they are word-for-word identical, then. – jscs May 30 '11 at 05:35