mirror of
https://github.com/containers/podman.git
synced 2026-03-13 08:01:19 +08:00
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user