format to 2 decimal places?

Get help using Construct 2

Post » Tue Sep 18, 2012 7:30 pm

If we have the players balance, which is a number set to 100 or 10.5 or similar, we want to show it as a text object to 2 decimal places. I can't find any way to do this, if you say

Global number balance = 100
...
   txtBalance set text to balance

it formats it to the min number of decimal places possible, e.g. "100.0" is displayed as "100" and 10.50 is displayed as "10.5" not "10.50"

Any ideas?
B
15
S
5
G
2
Posts: 357
Reputation: 3,691

Post » Tue Sep 18, 2012 8:55 pm

str(int(balance))&zeropad(int(balance*100)%100, 2)
B
79
S
24
G
54
Posts: 4,747
Reputation: 40,757

Post » Tue Sep 18, 2012 9:02 pm

Thank god you were here, I would have spent hours searching for a string function for this.

Ive put in a ".":

str(int(balance))&"."&zeropad(int(balance*100)%100, 2)

Thanks again!
B
15
S
5
G
2
Posts: 357
Reputation: 3,691


Return to How do I....?

Who is online

Users browsing this forum: Zebbi and 21 guests