Format Numbers
Portyman
Member, PRO Posts: 409
I am trying to format and display a stored integer with commas.
When i display text now, I get 45455454. I want to display 45,455,454. please help
When i display text now, I get 45455454. I want to display 45,455,454. please help
Comments
Anyway, in this situation, division and modulus are your friends but it may get clunky.
To get you thinking, if you have a number such as 12,345,678 you can break it apart with division and modulus:
12,345,678 modulus 1,000 = 678 (note this number)
12,345,678 - 678 = 12,345,000
12,345,000 divided 1,000 = 12,345
12,345 modulus 1,000 = 345 (note this number)
12,345 - 345 = 12,000
12,000 divided by 1,000 = 12 (note this number)
Store those noted values for display. If the score doesn't update too rapidly, normal change attribute may suffice. If it changes rapidly (i.e. a shoot-em up), then some constrain attributes would be needed OR you can roll them all into one LONG expression (but some of the sub-expressions will repeat themselves as you will find out).
One possible area of issue GS doesn't handle leading (or left padded) zeroes too well, so you may end up adding some rules for numbers such as 12,034,056 where the zeroes are at the leading edge of each number group (i.e. "034" or "056").
'$'..'345.00'
GS handles spaces and leading zeroes oddly at times, so you may have to play around with them if you encounter them. Sometimes, you can work around the issue by storing the value in an attribute and using the attribute in the display text behavior.
Thanks
What I am getting at is you are wasting processor resources in a game engine that can use all the resources it can get. I would finish your game without it, and if it performs very well on all devices (i.e. you get like 45+ frames per second on a 1st gen device), then think about implementing this and see if it degrades performance.
The other issue is, you never know when the devs will add a text formatting feature that could easily supplant your contrived routine(s).