In case someone needs it. Iposted as CODE, but the formatting was terrible, so I removed the CODE markup and... Didn't solve it... Anyway, code is here in case someone needs a fix to this problem. I'd be thankful if any MOD could format this post accordingly. Thank you.
`
'# My namespacing:
'# I know it's not a GDScript standard, I know, but I code for myself and I use the same namespacing
'# across other languages. I started doing this because when I tried someone else's library long ago,
'# a couple times my function names clashed with that library's ones, so I developed this particular
'# namespacing to prevent that from happening ever again and got used to it pretty fast.
'#
'# I love this namespacing, to be honest:
'# FunctionNames_ | _parameter_names | variable_names | s_structure_names | u_union_names
'# CONSTANT_NAMES | p_pointer_names | a_array_names | g_global_variables
'#
'# Notice that I often adopt long names for variables and functions. The reason is that self
'# descriptive entities' names, which are mostly self explanatory, albeit unconventionally long
'# and sometimes cumbersome to work with, effectively allow us to reduce the amount of comments
'# spread all over the code and eases its understanding. We just look at their names and immediately
'# realize what they are and what they do. e.g.: "separator_position" instead of "spos", "sp" or "sepp"
'# and "hud_score" instead of "hscore", "huds" or "hs". This particular file is loaded with
'# comments simply because I want to help people to get started, but most of them are not fundamentally
'# necessary for its understanding.
func FormatScore(score : int) -> String:
var formatted_score : String = str(_score)
# Let's try to display the thousands separator. This function does the trick. First, we check if the score has more than 4 digits.
# To do so, we convert the score variable to string and check its length. After that we divide the score by 1000.0 (float)
# and format the output to display 3 decimal places "%.3f". With that, we can use a decimal separator as if it was
# a thousand one. This is the simplest approach. Works flawlessly until 999.999
'# if str(score).length() > 3:
'# formatted_score = str("%.3f" % float(score / 1000.0))
# For numbers from the millions onward we need a loop. I don't need those extra separators because
# I'm pretty sure that no player will get near the 999.999 barrier and this is not major problem,
# just the million, billion, trillion, and so on, separators would be missing, but I'll do it anyway for
# the sake of doing it and eventually help those who need a solution to this problem.
# It may be useful if you are building an app, for example. Let's simply add a "." separator every 3 digits
# of a given number from the backwards:
var separator_position: int = str(_score).length()
if str(_score).length() > 3:
while separator_position > 3:
separator_position -= 3
formatted_score = str(_score).insert(separator_position,".")
'# # Same approach as above, but sets a distinct main separator "," :
'# var separator_position: int = str(score).length()
'# if str(score).length() > 3:
'# while separator_position > 3:
'# separator_position -= 3
'# if separator_position > 3:
'# formatted_score = str(score).insert(separator_position,".")
'# else:
'# formatted_score = str(score).insert(separator_position,",")
'# # If you want to display the decimals, we split the decimals from the integer, calculate the length of
'# # that integer and add the separators as always. After that, we format and append the decimals.
'# # It is necessary to manipulate the number as a string because if the last value is a "0", this character
'# # is suppressed from the string during math operations like (score / 100), for instance.
'# # Example: "1.200,50" would be "1.2,50"
'# # Let's suppose we want to deal with a two decimal places number. Be sure you declared the score variable
'# # as a float, of course:
'# formatted_score = str(floor(score)) # Stores the integer of score
'# var separator_position : int = str(floor(score)).length() # Stores the length of the score's integer
'# # Same deal as before to add the thousand separators
'# if str(floor(score)).length() > 3:
'# while separator_position > 3:
'# separator_position -= 3
'# formatted_score = str(score).insert(separator_position,".")
'# # The score_dec variable stores the decimal values of score as a string. To do so we strip score from
'# # its integer number and enforce two decimal places to be set. If you want to display 3 decimal places,
'# # just change it to "%.3f" and so on:
'# var score_dec : String = str("%.2f" % _score).get_slice(".", 1)
'# # Now, all we have to do is to append score_dec to hud_score. Output: 1.234.567,89
'# formatted_score = formatted_score + "," + score_dec
# For Debug:
'# printt(score, hud_score, score_dec)
return formatted_score
`