Quantcast

- XP further tweak to ensure formatting of numbers does not error.

urnati [07-16-24 - 12:33]
- XP further tweak to ensure formatting of numbers does not error.
Filename
TitanXP/TitanXP.lua
diff --git a/TitanXP/TitanXP.lua b/TitanXP/TitanXP.lua
index 6a725cf..4212893 100644
--- a/TitanXP/TitanXP.lua
+++ b/TitanXP/TitanXP.lua
@@ -84,15 +84,20 @@ end
 ---@return string
 local function comma_value(amount)
 	local formatted = ""
-	local sep = (TitanGetVar(TITAN_XP_ID, "UseSeperatorComma") and "," or ".")
-	local i, j, minus, int, fraction = tostring(amount):find('([-]?)(%d+)([.]?%d*)')

-	-- reverse the int-string and append a comma to all blocks of 3 digits
-	int = int:reverse():gsub("(%d%d%d)", "%1"..sep)
+	if type(amount) == "number" then
+		local sep = (TitanGetVar(TITAN_XP_ID, "UseSeperatorComma") and "," or ".")
+		local i, j, minus, int, fraction = tostring(amount):find('([-]?)(%d+)([.]?%d*)')

-	-- reverse the int-string back remove an optional comma and put the
-	-- optional minus and fractional part back
-	formatted = minus .. int:reverse():gsub("^"..sep, "") .. fraction
+		-- reverse the int-string and append a comma to all blocks of 3 digits
+		int = int:reverse():gsub("(%d%d%d)", "%1"..sep)
+
+		-- reverse the int-string back remove an optional comma and put the
+		-- optional minus and fractional part back
+		formatted = minus .. int:reverse():gsub("^"..sep, "") .. fraction
+	else
+		formatted = "0" -- 'silent' error
+	end
 	return formatted
 end