I want to use letters to describe how much u got in Money.

Example:

I have a variable name Money

``````var money = 12345
``````

And this is what i want to display

``````12345 to "1.2k"
``````

How do I do it?

Godot version 3.4.5
in Engine

That's going to take some custom code. Really, it shouldn't be too difficult, but you'll first need to define exactly how you'd expect ANY value to be displayed. So, think about that and come up with some rules that work for everything. Once you have those, converting that to code shouldn't be too hard (depending on the details).

+1 vote

In principle this isnt difficult but you would need to plan out how you would want to display it for given amounts. If it was me the way I would do it would be to first create a string of the value

``````var money_string = str(money)
``````

and after this you can base some logic on the length of your string for instance

``````if money_string.length() > 4:
print(money_string.left(1) + "." + money_string.right(1) + "k")
``````

would be one simplistic way to do this but may not be the way you want to show it. Try reading through the documentation here

https://docs.godotengine.org/en/stable/classes/class_string.html?highlight=string

and you can then plan out your logic.

by (3,328 points)
selected by

The number in his example is `12345` and the expected display is `1.2k`.
However if the number were `12999` would the expected display still be `1.2k`?
I would think the number expected would be `1.3k`.
Then there is the next level to consider. Would `1234567` be displayed as `1234.5k` or `1.2m`?
And the lower level. Does `123` get displayed as `0.1k`, `.1k`, or as it is?
Certainly it is not unworkable in any case however it definitely needs planning out as you say.

Well you can use something like

``````    print(money_string.substr(0, 1)+"."+money_string.substr(1, 1)+"k")
``````

but my point was that how he choses to make it look is up to him.

Thank you for helping me, I will try out the code, it really help
I will see about how to use it.