summaryrefslogtreecommitdiffstats
path: root/plugins.d/charts.d.plugin
diff options
context:
space:
mode:
authorLennart Weller <lhw@ring0.de>2016-04-21 12:27:29 +0000
committerLennart Weller <lhw@ring0.de>2016-04-21 12:27:29 +0000
commit30b94862648cdbf4f537337d2e2f01c369a9dee9 (patch)
treef0219dd8bd744fc09899bd0266402e05a4bff854 /plugins.d/charts.d.plugin
parentImported Upstream version 1.0.0 (diff)
downloadnetdata-30b94862648cdbf4f537337d2e2f01c369a9dee9.tar.xz
netdata-30b94862648cdbf4f537337d2e2f01c369a9dee9.zip
Imported Upstream version 1.1.0upstream/1.1.0
Diffstat (limited to 'plugins.d/charts.d.plugin')
-rwxr-xr-xplugins.d/charts.d.plugin22
1 files changed, 18 insertions, 4 deletions
diff --git a/plugins.d/charts.d.plugin b/plugins.d/charts.d.plugin
index 40c0356c8..27b294709 100755
--- a/plugins.d/charts.d.plugin
+++ b/plugins.d/charts.d.plugin
@@ -249,15 +249,26 @@ float2int() {
# the length of the multiplier - 1
l=$[ ${#m} - 1 ]
+ # check if the number is in scientific notation
+ if [[ ${f} =~ ^[[:space:]]*(-)?[0-9.]+(e|E)(\+|-)[0-9]+ ]]
+ then
+ # convert it to decimal
+ # unfortunately, this fork cannot be avoided
+ # if you know of a way to avoid it, please let me know
+ f=$(printf "%0.${l}f" ${f})
+ fi
+
# split the floating point number
# in integer (a) and decimal (b)
a=${f/.*/}
b=${f/*./}
- # prepend a zero to the integer part
- # if it is missing
+ # if the integer part is missing
+ # set it to zero
[ -z "${a}" ] && a="0"
- # strip leading zeros - base 10 convertion
+
+ # strip leading zeros from the integer part
+ # base 10 convertion
a=$[10#$a]
# check the length of the decimal part
@@ -266,13 +277,16 @@ float2int() {
then
# too many digits - take the most significant
b=${b:0:${l}}
+
elif [ ${#b} -lt ${l} ]
then
# too few digits - pad with zero on the right
local z="00000000000000000000000" r=$[l - ${#b}]
b="${b}${z:0:${r}}"
fi
- # strip leading zeros - base 10 convertion
+
+ # strip leading zeros from the decimal part
+ # base 10 convertion
b=$[10#$b]
# store the result