Skip to content

Instantly share code, notes, and snippets.

@Shilo
Created November 7, 2024 07:23
Show Gist options
  • Save Shilo/925a24772cc867be748cea2f791452ca to your computer and use it in GitHub Desktop.
Save Shilo/925a24772cc867be748cea2f791452ca to your computer and use it in GitHub Desktop.
Number formatt method to add thousand separator to number strings.
func format_number(number: Variant, thousand_separator: String = ",") -> String:
var number_str: String = str(number)
var start_index: int = number_str.find(".")
if start_index == -1:
start_index = number_str.length()
for i in range(start_index - 3, 0, -3):
number_str = number_str.insert(i, thousand_separator)
return number_str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment