This commit is contained in:
2025-02-23 14:47:07 +09:00
parent 52c6887887
commit 60279c4a49

View File

@@ -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