[vlc-commits] luahttp: make rounding function resilient to strings
Pierre Ynard
git at videolan.org
Fri May 18 05:32:19 CEST 2012
vlc/vlc-2.0 | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Fri May 18 04:15:23 2012 +0200| [6d85c42f7cb12b7cf7e4be24afe4efbd8315d80d] | committer: Pierre Ynard
luahttp: make rounding function resilient to strings
Because somehow strings are used to represent decimals...
Fixes #6815
(cherry picked from commit 78ee8bbd0478fda7ff55f8aa0d0a051be6784248)
Signed-off-by: Pierre Ynard <linkfanel at yahoo.fr>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=6d85c42f7cb12b7cf7e4be24afe4efbd8315d80d
---
share/lua/intf/modules/httprequests.lua | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/share/lua/intf/modules/httprequests.lua b/share/lua/intf/modules/httprequests.lua
index 1e53270..d527a6b 100644
--- a/share/lua/intf/modules/httprequests.lua
+++ b/share/lua/intf/modules/httprequests.lua
@@ -31,7 +31,13 @@ local dkjson = require ("dkjson")
--Round the number to the specified precision
function round(what, precision)
- if what then return math.floor(what*math.pow(10,precision)+0.5) / math.pow(10,precision) else return "" end
+ if type(what) == "string" then
+ what = common.us_tonumber(what)
+ end
+ if type(what) == "number" then
+ return math.floor(what*math.pow(10,precision)+0.5) / math.pow(10,precision)
+ end
+ return nil
end
--split text where it matches the delimiter
More information about the vlc-commits
mailing list