How do i format numbers

how do i make numbers shorter like 1000 to 1k, or 1500 to 1.5k, just know i will need it for number that are bigger than: 1,000,000,000,000,000,000,000,000,000,000,000

just know i arleady tried using an extension called “format number” and i couldn’t understand how it worked, any help is appreciated

Comma Separation Extension

Comma Spaces

1500 / 1000 =1.5
So all you would need to do is add K on end in text object
But i guess it would be problematic
BUT that you could deal with array

Where there is StrLength() expression which returns how many characters there are in string

So for example you have variable Cash
Cash = 1500
So StrLength(ToString(Cash)) = 4 cause there are 4 characters
Now there is expression StrRepeat()
So StrRepeat(0,StrLength(ToString(Cash))) would result in 0000
SOOOO StrRepeat(0,StrLength(ToString(Cash)-1)) would be 000
AND SOO ToNumber(1+StrRepeat(0,StrLength(ToString(Cash)-1))) would result in 1000
So now Cash / ToNumber(1+StrRepeat(0,StrLength(ToString(Cash)-1))) would result in 1.5

https://wiki.gdevelop.io/gdevelop5/all-features/expressions-reference/#text-manipulation

That extension appears available for downloading from GitHub, but I can’t see it in the GDevelop extension list - official or community.

Do not ask me about details cause i don’t know

But i often see ppl on discord asking over and over when their extension will be reviewed
AND i remember there are 2 ways for that
One will end up with us being able to find it in extension list in gdevelop
And other is to just be reviewed but not added which was faster

And maybe Reborn went with option 2?
OR i don’t remember it correctly and i am simply wrong

do i just make my code the last thing you wrote? if so do i just put “+ k” to add it? also, i would need it way far beyond 1T so I don’t know if it will work

You 1st need to understand that there are two types of values
Text and Number

For example NUMBER 1 + 1 = 2
It made calculation based on values you set

BUT TEXT 1 + 1 = 11
And it did not make any calculation but only joined together your values like lego blocks

So you could make variable called Suffix
And simply display Cash + Suffix
And now in events you could set suffix to M T K Z whatever based on length of Cash
You could even automate that process by using array

But 1st i need to apologize
My syntax was wrong
But i fixed it

ToString(Cash/ToNumber("1"+StrRepeat("0",StrLength(Cash)-1)))

1st number show Cash variable
2nd show how many characters are there
3rd by what you gonna divide Cash
4th result after divisiion

But that creates problem
Since in above screenshot it was 1500 and you wanted to show 1.5k
But when i changed it to 15000 it still show 1.5 and you would want 15k most likely

It means you would need to make A LOT of condition checking for length of Cash variable
And then based on it distribute different different number to divide by
For example 1000 and 10 000 and 100 000 should all return 3 zeros so 000
To divide by 1 000
So you would need to do event like
Cash length is above 3 but below 7
And now you need other variable which would be Divider so let’s call it that
Set Divider to 1000

And now formula would look like

ToString(Cash/Divider)

So my original assumption that you will be able to use static expression to get amount of what Divider should be is faulty
So do you really want to go with it?

Meaning you will need to manually set up range for each M K T Z B and whatever else?

It is doable just will take a lot of effort

so, what if i just use the format number extension?
i dont know how it works or what it adds, i just saw online that the extension fixes most people problems, if you could like share like a picture of what the event is supposed to look like and what “child array” variables should create, or whatever the extension needs to make it work, and for the bigger numbers, i can just nerf the upgrades, so that it dosent go to 1 milion after like 10 minutes of playing

Picture?
How about whole project?

This is example project with this extension

Just download it and look up whatever you need
I remember it was using arrays so check scene and/or global variables
Rest you will have in events

one last thing, i saw that i cant add the extension to an object, do i just add it in the “extension” tab of the whole project?

You know how
Both potato and banana are both food?
But only banana here is a fruit?

Same way every behavior is extension but not every extension is behavior

Behaviors are extensions you attach to object

Where any other extensions are standalone you do not attach to anything
You just need to have them in your project

BTW all behaviors you add to object will appear in extension list on left panel

So this is standalone extension you do not attach to anything just add it to your project

ok, i guess ill try seeing the example when i can, and I’ll try to add it to my project

1st open example
Look closely what is there even to a point you take screenshots
Then try to translate it to your project

Thanks it worked =D!!

1 Like