How to add percent sign in string format?

I want to get the string as "99.99%" from Double , and I used the format to get this:

 let rate = 99.99999 let str = String(format: "%.2f%", rate) // output 99.99 

And \% not allowed. So, how to add percent sign in string format, please help me!

+5
source share
2 answers

write two times%:

 rate = 99.99 let str = String(format: "%.2f%%", rate) 
+26
source

The% character is used in the printf statement. How would you place this character as part of the display?

You can do this using %% in the printf statement. For example, you can write printf ("10 %%") to display the output as 10% on the screen.

Hope it helps you :)

+3
source

All Articles