From 6504802e3cc455967d5eb7e5c15af0da33116f35 Mon Sep 17 00:00:00 2001 From: urnati Date: Tue, 16 Jul 2024 08:33:40 -0400 Subject: [PATCH] - XP further tweak to ensure formatting of numbers does not error. --- TitanXP/TitanXP.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 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 -- 1.7.9.5