]> git.sesse.net Git - vlc/commitdiff
luahttp: make rounding function resilient to strings
authorPierre Ynard <linkfanel@yahoo.fr>
Fri, 18 May 2012 02:15:23 +0000 (04:15 +0200)
committerPierre Ynard <linkfanel@yahoo.fr>
Fri, 18 May 2012 02:15:23 +0000 (04:15 +0200)
Because somehow strings are used to represent decimals...

Fixes #6815

share/lua/intf/modules/httprequests.lua

index 6dea512dcce1b65025b97b7ad7ff1bfd11c9e7e3..30c130d43d23bfa1280812f05a19ee5bf85cfb66 100644 (file)
@@ -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