diff options
author | baude <bbaude@redhat.com> | 2020-05-04 14:10:30 -0500 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2020-05-05 08:46:51 -0500 |
commit | b5a235df900a6471895111b4de5f80732f7f563a (patch) | |
tree | 7c6bb1cb564f6d69a0790fdea064a18bd0917ed1 /utils/utils.go | |
parent | 49107a5a2ee98793b4ecfaa0e1a6cacfdf5ccdd0 (diff) | |
download | podman-b5a235df900a6471895111b4de5f80732f7f563a.tar.gz podman-b5a235df900a6471895111b4de5f80732f7f563a.tar.bz2 podman-b5a235df900a6471895111b4de5f80732f7f563a.zip |
v2 podman stats
Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'utils/utils.go')
-rw-r--r-- | utils/utils.go | 19 |
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 +} |