How do I Convert large numbers to short format (1K, 1M, 1B)?

0 favourites
  • 6 posts
From the Asset Store
10 Warm & Emotional Soundtracks + loops (~1m. each)
  • In numbers I want to show all digits before the dot and 3 digits after the dot, here are some examples

    1885456 -> 1.885 M

    21025456 -> 2.102 M

    125568898789 -> 125.568 B

    I also want to set the digits after the dot myself, in some places I can only do it

    21025456 -> 2.1 M

    I want to use it as

    In the code I found, when 0 comes, it does not appear after 0.

  • Hi, here is a simple solution i made for you

    not sure what is all the int u using but the logic for decimals should be this

    round(Money / Divisor * 10) / 10 & Suffix

    Here is a full functional solution up to Sxtillions using Construct 10^N

    LargeNumberFormating

    in theory should show you any number as Sx,Qt,Q,T,B,M,K + .1 decimal like 2,155,123 Becomes 2.1milion

    Example uses 12 Events And 4 Global variables - for free users (and a function but the function can be changed to a Boolean condition all the same)

  • Hi, here is a simple solution i made for you

    not sure what is all the int u using but the logic for decimals should be this

    round(Money / Divisor * 10) / 10 & Suffix

    Here is a full functional solution up to Sxtillions using Construct 10^N

    LargeNumberFormating

    in theory should show you any number as Sx,Qt,Q,T,B,M,K + .1 decimal like 2,155,123 Becomes 2.1milion

    Example uses 12 Events And 4 Global variables - for free users (and a function but the function can be changed to a Boolean condition all the same)

    Thanks a lot for your help, just one thing, if the number is 19500000, it shows it as 19.5. Is there a way to always show it as 19.500 M?

    I want it to always be pleasing to the eye design wise

    or 19000000 19.0 M

    any touch and

    is touching object

    --

    touch on tap gesture

    What is the difference between the two I just started to learn and I don't know exactly

  • > Hi, here is a simple solution i made for you

    >

    > not sure what is all the int u using but the logic for decimals should be this

    >

    > round(Money / Divisor * 10) / 10 & Suffix

    >

    > Here is a full functional solution up to Sxtillions using Construct 10^N

    >

    >

    > LargeNumberFormating

    >

    > in theory should show you any number as Sx,Qt,Q,T,B,M,K + .1 decimal like 2,155,123 Becomes 2.1milion

    >

    > Example uses 12 Events And 4 Global variables - for free users (and a function but the function can be changed to a Boolean condition all the same)

    Thanks a lot for your help, just one thing, if the number is 19500000, it shows it as 19.5. Is there a way to always show it as 19.500 M?

    I want it to always be pleasing to the eye design wise

    or 19000000 19.0 M

    any touch and

    is touching object

    --

    touch on tap gesture

    What is the difference between the two I just started to learn and I don't know exactly

    redownload the example i updated it a few more times, should have all explanation and some more features inside.

    to show more decimals just increase "Decimals" 10 = 1 decimal , 100 = 2 decimals, 1000 = 3 decimals etc.

    i like to use on Tap as forces users to click and release quickly which counts as 1 click

    if u use "is touching " that creates a loop which means if user is touching or keeping pressed on 1 item long enough that action / condition will happen multiple times over N*ticks per second, so if u want for money to be awarded 1 time per click u need to use "on clicked" "on sprite touched" "on released" or "on pressed" "tapped"

    is touching is like "on holding" if u notice on Tap has 1 green arrow meaning happens 1 time per action

    if no arrow is a loop, unless is a condition to be checked if true then also becomes a loop unless specified "trigger event one time"

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • i wouldn't recommend using 1.959 M as might be confused with 1.9Billion and users will think your game is glitching max i would recommend using 2 decimals like 1.95M u cant confuse that with 1.95Billion even if is 999.95M

  • if you want to force 1 decimal even if is 0 after the front number just update the text in line 11 action

    "Money: " & round(Money / Divisor) & Suffix

    to

    "Money: " & round(Money / Divisor) &".0" & Suffix

    this will always force a .0 if number is perfectly round like 1,000,000 / 10,000,000 etc

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