Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
toastcrunch
481 PointsHow to you print % in a string, as in I want the print out looking like, "6 % 2 = ..."?
How do I print something that looks like
"6 % 2 = 0"
I'm trying,
NSLog(@"6 % 2 = %d", 6 % 2);
but am getting 2 errors. More percent conversions that data arguments and invalid conversion specifier.
I need to type instead NSLog(@"6 %% 2 = %d", 6 % 2);
but why do I need two %%s?
Thanks!
1 Answer
Jeremy Faith
Courses Plus Student 56,696 PointsThe % character is part of a format specifier such as %f or %d. If you want to print a % in a string you need to use the escape code %%. You can visit Mac Developer Library for more information about string formatting.
toastcrunch
481 Pointstoastcrunch
481 PointsThanks, Jeremy!