From 6609b642dc972597cba85391ce6b8d72a9d25e53 Mon Sep 17 00:00:00 2001 From: Ishaan Bhardwaj Date: Wed, 20 Jan 2021 10:53:39 -0500 Subject: [PATCH] formatBigNum prettifier --- funcs.lua | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/funcs.lua b/funcs.lua index 77a8284..5f5f1c7 100644 --- a/funcs.lua +++ b/funcs.lua @@ -56,9 +56,19 @@ end function formatBigNum(number) -- returns a string representing a number with commas as thousands separator (e.g. 12,345,678) - local s = string.format("%d", number) - local pos = string.len(s) % 3 - if pos == 0 then pos = 3 end + local s + if type(number) == "number" then + s = string.format("%d", number) + elseif type(number) == "string" then + if not tonumber(number) then + return + else + s = number + end + else + return + end + local pos = Mod1(string.len(s), 3) return string.sub(s, 1, pos) .. string.gsub(string.sub(s, pos+1), "(...)", ",%1") end