percentage

I want to print a percentage to the screen. How can I only print 2 decimal places.

Use String with format:

let percentString = String(format: "%4.2f", valueToPrint) + " %"

Thank you very much. This is what I got in my program: tipc = String(tipo / Double(cost)! * 100) let percentString = String(format: "%4.2f", tipc) + " %"
tipc = percentString
It prints -0.00%.
Thanks again.

What did I do wrong? If tipc is 50.0 or 12.7446537 percentString is always -0.00 or 0.00. Please help. Thank you.

??

Claude31,

What's wrong with my code? Thanks

percentage
 
 
Q