fix for decimal points/undercutting by 1c

This commit is contained in:
Manuel Simon Hirsig
2016-02-07 15:59:49 +01:00
parent 61efe10681
commit cd10808a1d
6 changed files with 16 additions and 12 deletions
+6 -2
View File
@@ -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)