mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 03:25:23 +09:00
.
This commit is contained in:
@@ -24,7 +24,6 @@ local function format_n(amount)
|
||||
if math.abs(amount) < 0.009 then
|
||||
return "0.00"
|
||||
end
|
||||
|
||||
local suffix = ""
|
||||
local suffix_list = {
|
||||
["T"] = 1e12,
|
||||
@@ -32,7 +31,6 @@ local function format_n(amount)
|
||||
["M"] = 1e6,
|
||||
["k"] = 1e3
|
||||
}
|
||||
|
||||
local scale = 1
|
||||
for letter, limit in pairs(suffix_list) do
|
||||
if math.abs(amount) >= limit then
|
||||
@@ -41,19 +39,15 @@ local function format_n(amount)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
local scaled_value = amount / scale
|
||||
local formatted = string.format("%.2f", scaled_value)
|
||||
|
||||
-- Split into integer and fractional parts
|
||||
local integer_part, fractional_part = formatted:match("^(%-?%d+)%.(%d+)$")
|
||||
integer_part = integer_part or formatted
|
||||
fractional_part = fractional_part or "00"
|
||||
|
||||
-- Add commas to integer part
|
||||
integer_part = integer_part:reverse():gsub("(%d%d%d)", "%1,"):reverse()
|
||||
integer_part = integer_part:gsub("^,", ""):gsub("-,", "-")
|
||||
|
||||
-- Handle numbers below 1000 without suffix
|
||||
if scale == 1 then
|
||||
-- Remove trailing .00 for whole numbers
|
||||
@@ -62,13 +56,9 @@ local function format_n(amount)
|
||||
end
|
||||
return string.format("%s.%s", integer_part, fractional_part)
|
||||
end
|
||||
|
||||
-- Combine parts and add suffix
|
||||
return string.format("%s.%s %s",
|
||||
integer_part,
|
||||
fractional_part,
|
||||
suffix
|
||||
):gsub("%.?0+ %k$", " "..suffix) -- Clean up trailing zeros
|
||||
-- Clean up trailing zeros
|
||||
return string.format("%s.%s %s", integer_part, fractional_part, suffix):gsub("%.?0+ %k$", " " .. suffix)
|
||||
end
|
||||
|
||||
--- Display group
|
||||
|
||||
Reference in New Issue
Block a user