From c05eb5f35384be2e96bb6ab24cb134caa9458c92 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Wed, 27 Jan 2016 12:48:03 +0100 Subject: [PATCH] fractional money patterns implemented --- money.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/money.lua b/money.lua index c75b734..1c15a7a 100644 --- a/money.lua +++ b/money.lua @@ -64,15 +64,15 @@ function m.from_string(value) value = gsub(gsub(value, '\124c([0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])', ''), '\124r', '') -- extract gold/silver/copper values - local gold = tonumber(({strfind(value, '([0-9]+)g')})[3]) - local silver = tonumber(({strfind(value, '([0-9]+)s')})[3]) - local copper = tonumber(({strfind(value, '([0-9]+)c')})[3]) + local gold = tonumber(({strfind(value, '(%d*%.?%d+)g')})[3]) + local silver = tonumber(({strfind(value, '(%d*%.?%d+)s')})[3]) + local copper = tonumber(({strfind(value, '(%d*%.?%d+)c')})[3]) -- if not gold and not silver and not copper then return end -- test that there are no extra characters (other than spaces) - value = gsub(value, '[0-9]+g', '', 1) - value = gsub(value, '[0-9]+s', '', 1) - value = gsub(value, '[0-9]+c', '', 1) + value = gsub(value, '%d*%.?%d+g', '', 1) + value = gsub(value, '%d*%.?%d+s', '', 1) + value = gsub(value, '%d*%.?%d+c', '', 1) if strfind(value, '%S') then return 0 end return ((gold or 0) * COPPER_PER_GOLD) + ((silver or 0) * COPPER_PER_SILVER) + (copper or 0)