[Solved!] Global Variable number question

For questions about using Classic.

Post » Sun May 01, 2011 4:29 pm

Hello,

I've another question! I use a global variable to show your highscore, but the score got many decimals. After some searching, I found out that you can remove that with round(global('Score Level 1')). What I want is two numbers after the comma, (2.34 seconds) and not (2 seconds). How can I achieve that?

Thank you!
Thijs
B
1
G
1
Posts: 4
Reputation: 433

Post » Sun May 01, 2011 4:41 pm

From the wiki:

FormatDecimal(number, N)
Returns a string with number given to N decimal places, eg. FormatDecimal(5.7777, 2) gives 5.78

So it would be FormatDecimal(global('Score Level 1'), 2)
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sun May 01, 2011 5:01 pm

Oh, great! It's working perfect. :D Thanks.
B
1
G
1
Posts: 4
Reputation: 433

Post » Sun May 01, 2011 5:17 pm

Just for the record (and for the curious):
You can also always create your own decimal places. But you need pv's or globals for the interim results to avoid rounding errors.

number n = 23.452612
you want three decimal places

1) int/round/ceil/floor(n*1000); store the result in a variable v. [v = 23452 or 23453, depending on your rounding choice]
2) result = v / 1000 [result = 23.452 or 23.453, depending on your rounding choice]
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests