Topic was automatically imported from the old Question2Answer platform.
Asked By
BQKdev
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?
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).
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
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
and you can then plan out your logic.
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.