summaryrefslogtreecommitdiff
path: root/libpod/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/util.go')
-rw-r--r--libpod/util.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/libpod/util.go b/libpod/util.go
index 61089b525..de5c3ff31 100644
--- a/libpod/util.go
+++ b/libpod/util.go
@@ -9,6 +9,8 @@ import (
"github.com/containers/image/signature"
"github.com/containers/image/types"
+ "github.com/pkg/errors"
+ "strconv"
)
// Runtime API constants
@@ -76,3 +78,21 @@ func GetPolicyContext(path string) (*signature.PolicyContext, error) {
}
return signature.NewPolicyContext(policy)
}
+
+// 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
+}