mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-31 21:01:39 +09:00
.
This commit is contained in:
@@ -26,9 +26,9 @@ local function format_n(amount)
|
|||||||
end
|
end
|
||||||
local suffix = ""
|
local suffix = ""
|
||||||
local suffix_list = {
|
local suffix_list = {
|
||||||
["G"] = 1e9,
|
[" G"] = 1e9,
|
||||||
["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
|
||||||
@@ -38,16 +38,11 @@ local function format_n(amount)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local formatted = string.format("%.2f", amount / scale)
|
local formatted = string.format("%.2f%s", amount / scale, suffix)
|
||||||
-- 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
|
|
||||||
-- Add commas to integer part
|
-- Add commas to integer part
|
||||||
integer_part = integer_part:reverse():gsub("(%d%d%d)", "%1,"):reverse()
|
return string.format("%s.%s%s", (integer_part or formatted):reverse():gsub("(%d%d%d)", "%1,"):reverse():gsub("^,", ""):gsub("-,", "-"), (fractional_part or "00"), suffix):gsub("%.00([ ]?[GMk])$", "%1")
|
||||||
integer_part = integer_part:gsub("^,", ""):gsub("-,", "-")
|
|
||||||
-- Handle numbers below 1000 without suffix
|
|
||||||
-- Combine parts and add suffix
|
|
||||||
return string.format("%s.%s%s", integer_part, fractional_part or "00", (suffix == "" and "") or (" " .. suffix)):gsub("%.?0+ %k$", " " .. suffix)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Display group
|
--- Display group
|
||||||
|
|||||||
Reference in New Issue
Block a user