I want to have a percentage sign in my string after a digit. Something like this: 75%.
How can I have this done? I tried:
[NSString stringWithFormat:@"%d\%", someDigit]; But it didn't work for me.
You can do this by using %% in the printf statement. For example, you can write printf(“10%%”) to have the output appear as 10% on the screen.
In Java, the modulus operator is a percent sign, %. The syntax is the same as for other operators: int quotient = 7 / 3; int remainder = 7 % 3; The first operator, integer division, yields 2.
The code for percent sign in NSString format is %%. This is also true for NSLog() and printf() formats.
The escape code for a percent sign is "%%", so your code would look like this
[NSString stringWithFormat:@"%d%%", someDigit]; Also, all the other format specifiers can be found at Conceptual Strings Articles
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With