[Solved!] Global Variable number question

This forum is currently in read-only mode.
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • 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

  • 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)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Oh, great! It's working perfect. Thanks.

  • 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]

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)