webmcp

view framework/env/parse/percentage.lua @ 562:328f120924a2

Removed if-clause when initializing file descriptor set to avoid compiler warning for mondelefant_conn_try_wait
author jbe
date Fri Feb 05 15:51:39 2021 +0100 (2021-02-05)
parents 9fdfb27f8e67
children
line source
1 function parse.percentage(str, dest_type, options)
2 local str = parse._pre_fold(str)
3 local dest_type = dest_type or atom.number
4 local options = table.new(options)
5 options.precision = options.precision or 0
6 if options.decimal_shift == true then
7 options.decimal_shift = options.precision + 2
8 end
9 local f = parse.decimal(string.match(str, "^ *([^%%]*) *%%? *$"), dest_type, options)
10 if dest_type == atom.number then
11 if f then
12 return f / 100
13 end
14 elseif dest_type == atom.integer then
15 if f then
16 f = f / 100
17 if atom.is_integer(f) then
18 return f
19 else
20 return atom.integer.invalid
21 end
22 end
23 elseif dest_type == atom.fraction then
24 if f then
25 return f / 100
26 end
27 else
28 error("Missing or invalid destination type for parsing.")
29 end
30 end

Impressum / About Us