Created
November 7, 2024 07:23
-
-
Save Shilo/925a24772cc867be748cea2f791452ca to your computer and use it in GitHub Desktop.
Number formatt method to add thousand separator to number strings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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