fix for decimal points/undercutting by 1c
This commit is contained in:
@@ -7,7 +7,7 @@ local COPPER_TEXT = '|cffeda55fc|r'
|
||||
local COPPER_PER_SILVER = 100
|
||||
local COPPER_PER_GOLD = 10000
|
||||
|
||||
function m.to_string(money, pad, trim, color, no_color)
|
||||
function m.to_string(money, pad, trim, decimal_points, color, no_color)
|
||||
|
||||
local is_negative = money < 0
|
||||
money = abs(money)
|
||||
@@ -16,6 +16,10 @@ function m.to_string(money, pad, trim, color, no_color)
|
||||
-- local copper = Aux.round(mod(money, COPPER_PER_SILVER))
|
||||
local copper = mod(money, COPPER_PER_SILVER)
|
||||
|
||||
if decimal_points then
|
||||
copper = tonumber(format('%.'..decimal_points..'f', copper))
|
||||
end
|
||||
|
||||
local gold_text, silver_text, copper_text
|
||||
if no_color then
|
||||
gold_text, silver_text, copper_text = 'g', 's', 'c'
|
||||
@@ -78,7 +82,7 @@ function m.from_string(value)
|
||||
value = gsub(value, '%d*%.?%d+c', '', 1)
|
||||
if strfind(value, '%S') then return 0 end
|
||||
|
||||
return Aux.round(((gold or 0) * COPPER_PER_GOLD) + ((silver or 0) * COPPER_PER_SILVER) + (copper or 0))
|
||||
return ((gold or 0) * COPPER_PER_GOLD) + ((silver or 0) * COPPER_PER_SILVER) + (copper or 0)
|
||||
end
|
||||
|
||||
function m.format_number(num, pad, color)
|
||||
|
||||
Reference in New Issue
Block a user