class_name StringUtilities extends Node

func seconds_to_hms(seconds: float) -> String:
	var ms = fmod(seconds, 1) * 100
	var s = fmod(seconds, 60)
	var m = fmod(seconds, 3600) / 60

	var formatted : String = "%02d:%02d:%02d" % [m, s, ms]

	return formatted

####
## Formats the given number with commas every 3 digits.	
####
func format_number(number: int) -> String:
	# Handle negative numbers by adding the "minus" sign in advance, as we discard it
	# when looping over the number.
	var formatted_number := "-" if sign(number) == -1 else ""
	var index := 0
	var number_string := str(abs(number))

	for digit in number_string:
		formatted_number += digit
        
		var counter := number_string.length() - index
        
		# Don't add a comma at the end of the number, but add a comma every 3 digits
		# (taking into account the number's length).
		if counter >= 2 and counter % 3 == 1:
			formatted_number += ","
            
		index += 1
    
	return formatted_number

func float_to_percentage(value: float) -> String:
	return "%d%%" % int(value * 100)