Print % sign

I am using the line:

   con.Screen.print("Battery %.2f % full", (Brain.Battery.voltage()/Brain.Battery.capacity())*100); 

and I get:
Battery 37.69 full when I want Battery 37.69% full

I tried searching the forum, but could not find anything.
Please Help :slight_smile:
Thanks in advance

Try:

   con.Screen.print("Battery %.2f%% full", (Brain.Battery.voltage()/Brain.Battery.capacity())*100); 

% is an escape character, so if you want an actual % in the output you have to put 2 in a row.

7 Likes

Thank you. I will try this out on Tuesday, and tell you how it goes. :slight_smile:

I want to add a bit more onto this. This document is very useful:


Also, if you’re unsure about the β€œ.2” is before f, it’s basically stating how many decimal places to provide after the period.
Source
If you want to know about what floats, doubles, etc. do and how they work, check out my tutorial video explaining what they mean here.

2 Likes