Page 1 of 1
How to show thousands separator for variable?
Posted: Sun Apr 23, 2017 2:51 am
by sapiboonggames
Hello guys, I'm back with another question
As the subject says, do you know how to show thousands separator for variable?
Let's say:
Right now, if I show money by using [money], it's displayed as "10000", is there any way to display it as "10,000" or "10.000"?
Thanks!
Re: How to show thousands separator for variable?
Posted: Sun Apr 23, 2017 3:29 am
by Ocelot
The obvious way: transform number to string, insert separator as needed and print that string instead of raw number. You can easily do that using format: $ money_string = '{:,}'.format(money)
Correct way would be to define your class to hold money, with proper methods to add and substract money with invariant checking and override __repr__() magic method, so your class would be properly displayed whenever you need it with actual values.
Re: How to show thousands separator for variable?
Posted: Sun Apr 23, 2017 3:39 am
by sapiboonggames
Ocelot wrote:The obvious way: transform number to string, insert separator as needed and print that string instead of raw number. You can easily do that using format: $ money_string = '{:,}'.format(money)
Correct way would be to define your class to hold money, with proper methods to add and substract money with invariant checking and override __repr__() magic method, so your class would be properly displayed whenever you need it with actual values.
Thanks!
I used the transform number to string method, and it works great.
Re: How to show thousands separator for variable?
Posted: Sun Apr 23, 2017 3:52 am
by Imperf3kt
I looked at the explanation and scratched my head. I guess I don't even understand a lot of python yet.
Re: How to show thousands separator for variable?
Posted: Sun Apr 23, 2017 3:54 am
by meyaoi
Imperf3kt wrote:I looked at the explanation and scratched my head. I guess I don't even understand a lot of python yet.
I don't really understand the 2nd method too
But the 1st method is simple enough.
You just need to display money_string variable after transforming it instead of the previous money variable.
Re: How to show thousands separator for variable?
Posted: Thu Jun 11, 2020 3:56 am
by HammeredEnt
Hi team,
I’m trying to get this to work myself but I’m clearly doing something wrong. Can someone spot-check my work here?
My variable is named 'jackpotfunds'. Prior to the start label of the script I’ve got:
Code: Select all
default jackpotfunds = 1000
$ money = '{:,}'.format(jackpotfunds)
In the game itself, I’m using the following to display that variable with the comma separator :
but it's literally coming up:
"You now have [money]"
rather than displaying the formatted string.
I primarily want to use this in an inventory screen (where the coding may be different) but I figure if I need to get that working in regular dialogue first and then hopefully it won't be different for the other screen.
Help?
Re: How to show thousands separator for variable?
Posted: Thu Jun 11, 2020 7:19 am
by Remix
Your
Code: Select all
$ money = '{:,}'.format(jackpotfunds)
line is only running once and the point where you have the output is either before that or through a save that did not include that variable
As [] interpolation can use pyFormat, just use:
Re: How to show thousands separator for variable?
Posted: Thu Jun 11, 2020 9:13 am
by HammeredEnt
That did the trick. Thanks Remix!