How do I show and calculate my numbers correctly

0 favourites
  • 4 posts
From the Asset Store
Jump on numbers in the proper order and reach the sun!
  • Hi guys,

    I'm having some issues with my game and it's numbers.

    I want to create a balance that has 4 decimals. So my number start with 0.0000.

    As 1.0000 stands for "1" and 12.3000 stands for "12.3".

    At this moment i use round(N * 10000) / 10000 to show my numbers like 0.001 but i can't fix the fourth 0.

    Also some of my objects have the price of 0.0001 which will not be possible. I can set a instance variable up to 3 decimals. So 0.001 is possible but 0.0001 is not.

    My exact goal is:

    Start out with 0.0001

    Able to display 1.0000 as 1.0000

    Able to display 10.0000 as 10.0000

    Able to display 100.0000 as 100.0000

    Able to display 1000.0000 as 1K

    Able to display 1200.0000 as 1.2K

    Able to display 10000.0000 as 10K

    Able to display 12000.0000 as 12K

    Able to display 100000.0000 as 100K

    Able to display 120000.0000 as 120K

    Able to display 1000000.0000 as 1M

    Able to display 1200000.0000 as 12M

    ETC.

    Any one here able to help me into the right direction?

  • This will format the number as "1.0000"

    variable decimal=0
    Set decimal to round((number-int(number))*10000)
    Set text "txtNumber" to -> int(number) & "." & zeropad(decimal,4)
     [/code:1lytxge9]
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for your reply!

    This works perfect and i want to use this from 0.0001 till 999.9999 But after that i want to start using "K" as thousand, "M" as million, "B" as billion etc.

    This means that in the K is should change from xxx.xxxx to 1.001K

    Any idea what the math on that one is? All it has to do actually is move the dot 3 times to the left.

    Thanks in advance!

  • You can do something like this:

    If N>=1000 then Set Text to (round(N* 10) / 10000) & "K"

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