Limit number of decimal places in canvas text element
Dear Forum,
I hope you are doing well.
For a canvas text element that displays the value of a variable, I would like to limit the number of decimal places to be displayed to two. I already used the %.2f operator in another text element and it works perfectly, however for the current one it does not work. In the one that is working, I only display the variable and no additional text, therefore I suspect that the problem has to do with the entire formatting of the text where I use the .format.
This is the variable where it works:
my_canvas["upper_left_amount"] = Text("%.2f"%states[l]["upper_safe_amount"],center=True, x=-256, y=-175)
And this is the one where it does not function yet:
my_canvas["expected_value_right"] = Text("Durchschnitt:{expected_value_right}".format(expected_value_right = "%.2f"%states[l]["expected_value_lottery"]),center=True, x=256, y=0, font_size=22)
Do you have any recommendation of how I could fix this issue? I would prefer to change the formatting in the text element and to not change the original variable for consistency reasons.
Thanks a lot in advance & best regards,
Sarah
Comments
The issue has already been resolved in the meantime, so this can be closed :)