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
17
S
6
G
3
Posts: 370
Reputation: 3,942

Post » Tue Sep 18, 2012 8:55 pm

str(int(balance))&zeropad(int(balance*100)%100, 2)
B
88
S
30
G
89
Posts: 5,107
Reputation: 60,325

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
17
S
6
G
3
Posts: 370
Reputation: 3,942


Return to How do I....?

Who is online

Users browsing this forum: dzert14 and 10 guests