From e29ea6288a04100850efad7f1aa0cd747b82dc78 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Sat, 20 Feb 2010 03:24:42 +0100 Subject: helpers: uformat helper replaces formatting done by widgets --- helpers.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'helpers.lua') diff --git a/helpers.lua b/helpers.lua index c731ae8..e8d6d6c 100644 --- a/helpers.lua +++ b/helpers.lua @@ -12,7 +12,8 @@ local io = { open = io.open } local setmetatable = setmetatable local string = { sub = string.sub, - gsub = string.gsub + gsub = string.gsub, + format = string.format } -- }}} @@ -51,6 +52,16 @@ function format(format, args) end -- }}} +-- {{{ Format units to one decimal point +function uformat(array, key, value, unit) + for u, v in pairs(unit) do + array["{"..key.."_"..u.."}"] = string.format("%.1f", value/v) + end + + return array +end +-- }}} + -- {{{ Escape a string function escape(text) local xml_entities = { -- cgit v1.2.3