webmcp

annotate framework/env/parse/percentage.lua @ 405:c5f9a1b2f225

Updated year of copyright notice
author jbe
date Wed Jan 06 02:54:45 2016 +0100 (2016-01-06)
parents 9fdfb27f8e67
children
rev   line source
jbe/bsw@0 1 function parse.percentage(str, dest_type, options)
jbe/bsw@0 2 local str = parse._pre_fold(str)
jbe/bsw@0 3 local dest_type = dest_type or atom.number
jbe/bsw@0 4 local options = table.new(options)
jbe/bsw@0 5 options.precision = options.precision or 0
jbe/bsw@0 6 if options.decimal_shift == true then
jbe/bsw@0 7 options.decimal_shift = options.precision + 2
jbe/bsw@0 8 end
jbe/bsw@0 9 local f = parse.decimal(string.match(str, "^ *([^%%]*) *%%? *$"), dest_type, options)
jbe/bsw@0 10 if dest_type == atom.number then
jbe/bsw@0 11 if f then
jbe/bsw@0 12 return f / 100
jbe/bsw@0 13 end
jbe/bsw@0 14 elseif dest_type == atom.integer then
jbe/bsw@0 15 if f then
jbe/bsw@0 16 f = f / 100
jbe/bsw@0 17 if atom.is_integer(f) then
jbe/bsw@0 18 return f
jbe/bsw@0 19 else
jbe/bsw@0 20 return atom.integer.invalid
jbe/bsw@0 21 end
jbe/bsw@0 22 end
jbe/bsw@0 23 elseif dest_type == atom.fraction then
jbe/bsw@0 24 if f then
jbe/bsw@0 25 return f / 100
jbe/bsw@0 26 end
jbe/bsw@0 27 else
jbe/bsw@0 28 error("Missing or invalid destination type for parsing.")
jbe/bsw@0 29 end
jbe/bsw@0 30 end

Impressum / About Us