summaryrefslogtreecommitdiff
path: root/utils/utils.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-05-05 17:29:56 +0200
committerGitHub <noreply@github.com>2020-05-05 17:29:56 +0200
commit9db97dbab8b777b3c9b868cdab62cb7b46839f95 (patch)
treecf9556b1c2991fa30b7c23398ec44a636bfbad82 /utils/utils.go
parente6235ef8f1a3111f8f1afbb1bf64f0e6da704a5b (diff)
parentb5a235df900a6471895111b4de5f80732f7f563a (diff)
downloadpodman-9db97dbab8b777b3c9b868cdab62cb7b46839f95.tar.gz
podman-9db97dbab8b777b3c9b868cdab62cb7b46839f95.tar.bz2
podman-9db97dbab8b777b3c9b868cdab62cb7b46839f95.zip
Merge pull request #6080 from baude/v2stats
v2 podman stats
Diffstat (limited to 'utils/utils.go')
-rw-r--r--utils/utils.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/utils/utils.go b/utils/utils.go
index cf58ca3fb..27ce1821d 100644
--- a/utils/utils.go
+++ b/utils/utils.go
@@ -6,6 +6,7 @@ import (
"io"
"os"
"os/exec"
+ "strconv"
"strings"
"github.com/containers/storage/pkg/archive"
@@ -125,3 +126,21 @@ func Tar(source string) (io.ReadCloser, error) {
logrus.Debugf("creating tarball of %s", source)
return archive.Tar(source, archive.Uncompressed)
}
+
+// RemoveScientificNotationFromFloat returns a float without any
+// scientific notation if the number has any.
+// golang does not handle conversion of float64s that have scientific
+// notation in them and otherwise stinks. please replace this if you have
+// a better implementation.
+func RemoveScientificNotationFromFloat(x float64) (float64, error) {
+ bigNum := strconv.FormatFloat(x, 'g', -1, 64)
+ breakPoint := strings.IndexAny(bigNum, "Ee")
+ if breakPoint > 0 {
+ bigNum = bigNum[:breakPoint]
+ }
+ result, err := strconv.ParseFloat(bigNum, 64)
+ if err != nil {
+ return x, errors.Wrapf(err, "unable to remove scientific number from calculations")
+ }
+ return result, nil
+}