From 7621866e8a88add8cd2a03b08c3608a74740357f Mon Sep 17 00:00:00 2001 From: urnati Date: Tue, 16 Jul 2024 08:52:01 -0400 Subject: [PATCH] - Gold : Use same code as XP to add cooma / period separator. Removes while true loop. --- TitanGold/TitanGold.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/TitanGold/TitanGold.lua b/TitanGold/TitanGold.lua index df7de43..053dac6 100644 --- a/TitanGold/TitanGold.lua +++ b/TitanGold/TitanGold.lua @@ -59,6 +59,7 @@ end ---@param amount number ---@return string local function comma_value(amount) +--[===[ local formatted = tostring(amount) local k local sep = (TitanGetVar(TITAN_GOLD_ID, "UseSeperatorComma") and "UseComma" or "UsePeriod") @@ -70,6 +71,25 @@ local function comma_value(amount) end end return formatted +--]===] + -- Jul 2024 Use same code as XP + local formatted = "" + + if type(amount) == "number" then + local sep = (TitanGetVar(TITAN_GOLD_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) + + -- 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 ---local Take the total cash and make it into a nice, colorful string of g s c (gold silver copper) -- 1.7.9.5