From 4fed5dc38d6abfc6cfcf45cb4ff10af8c66e59c4 Mon Sep 17 00:00:00 2001 From: mikigoalie Date: Fri, 26 May 2023 01:06:28 +0200 Subject: [PATCH] feat(imports/math): groupdigits (#338) --- imports/math/shared.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/imports/math/shared.lua b/imports/math/shared.lua index ace7896f..e4782f1c 100644 --- a/imports/math/shared.lua +++ b/imports/math/shared.lua @@ -90,4 +90,13 @@ function math.tohex(n, upper) return upper and n:upper() or n end -return lib.math +---Converts input number into grouped digits +---@param number number +---@param seperator? string +---@return string +function math.groupdigits(number, seperator) -- credit http://richard.warburton.it + local left,num,right = string.match(number,'^([^%d]*%d)(%d*)(.-)$') + return left..(num:reverse():gsub('(%d%d%d)','%1' .. (seperator or ',')):reverse())..right +end + +return lib.math \ No newline at end of file