CREATE YOUR AI CUM SLUT ON CANDY.AI TRY FOR FREE
x

Ren'Py Ren'py printing percentages to 2 decimal places

mordred93

Well-Known Member
Jul 21, 2017
1,590
2,413
Okay - this seems really darned basic, but I have been running into this for about 6 hours of research, I can get this to work in actual python, but not ren'py. I want to show the actual percentage of a grade, to two decimal places. First I calculate the grade:

$grade_percent = grade_score / grade_total * 100

Then I want to print it.

mc "[Student_Name], You received a [grade_percent] %% after answering [grade_score] correct out of [grade_total]"

When I do this, I get the outputs of the following for3 runs:
You received a 100.0% after answering 4 correct out of 4
You received a 66.666666666666666666666666% after answering 2 correct out of 3
You received a 50.0% after answering 1 correct out of 2

I want to format it with 2 decimal places. So the answers are 100.00%, 66.66%, 50.00% respectively (or one if that is all I can do). I thought I could do [grade_percent:.2] but it gives me an exponent instead of a number (which is not human readable). Any help would be appreciated.
 

Winterfire

Forum Fanatic
Respected User
Game Developer
Sep 27, 2018
5,527
8,062
Okay - this seems really darned basic, but I have been running into this for about 6 hours of research, I can get this to work in actual python, but not ren'py. I want to show the actual percentage of a grade, to two decimal places. First I calculate the grade:

$grade_percent = grade_score / grade_total * 100

Then I want to print it.

mc "[Student_Name], You received a [grade_percent] %% after answering [grade_score] correct out of [grade_total]"

When I do this, I get the outputs of the following for3 runs:
You received a 100.0% after answering 4 correct out of 4
You received a 66.666666666666666666666666% after answering 2 correct out of 3
You received a 50.0% after answering 1 correct out of 2

I want to format it with 2 decimal places. So the answers are 100.00%, 66.66%, 50.00% respectively (or one if that is all I can do). I thought I could do [grade_percent:.2] but it gives me an exponent instead of a number (which is not human readable). Any help would be appreciated.
Try [grade_percent:.2f] otherwise Round() function should work just as fine.
 

mordred93

Well-Known Member
Jul 21, 2017
1,590
2,413
Okay ... I was trying [grade_percent:.2%] which was giving me an exponent. Looks like the ":.2f" worked. I looked for hours trying to find that, and never saw that as an option. Thanks, as I said, Simple, but just could not find it. I tested it and validated.