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