diff --git a/cmd/podman/containers/stats.go b/cmd/podman/containers/stats.go index da6e24cccf..dd275e6d9e 100644 --- a/cmd/podman/containers/stats.go +++ b/cmd/podman/containers/stats.go @@ -15,7 +15,6 @@ import ( "github.com/containers/podman/v5/cmd/podman/validate" "github.com/containers/podman/v5/libpod/define" "github.com/containers/podman/v5/pkg/domain/entities" - "github.com/containers/podman/v5/utils" "github.com/docker/go-units" "github.com/spf13/cobra" ) @@ -243,12 +242,7 @@ func (s *containerStats) MemUsageBytes() string { } func floatToPercentString(f float64) string { - strippedFloat, err := utils.RemoveScientificNotationFromFloat(f) - if err != nil { - // If things go bazinga, return a safe value - return "--" - } - return fmt.Sprintf("%.2f", strippedFloat) + "%" + return fmt.Sprintf("%.2f%%", f) } func combineHumanValues(a, b uint64) string { diff --git a/libpod/util_test.go b/libpod/util_test.go deleted file mode 100644 index baa596f777..0000000000 --- a/libpod/util_test.go +++ /dev/null @@ -1,20 +0,0 @@ -//go:build !remote - -package libpod - -import ( - "testing" - - "github.com/containers/podman/v5/utils" - "github.com/stretchr/testify/assert" -) - -func TestRemoveScientificNotationFromFloat(t *testing.T) { - numbers := []float64{0.0, .5, 1.99999932, 1.04e+10} - results := []float64{0.0, .5, 1.99999932, 1.04} - for i, x := range numbers { - result, err := utils.RemoveScientificNotationFromFloat(x) - assert.NoError(t, err) - assert.Equal(t, result, results[i]) - } -} diff --git a/pkg/domain/infra/abi/pods_stats.go b/pkg/domain/infra/abi/pods_stats.go index 5576f7680f..8ece02c2c6 100644 --- a/pkg/domain/infra/abi/pods_stats.go +++ b/pkg/domain/infra/abi/pods_stats.go @@ -10,7 +10,6 @@ import ( "github.com/containers/podman/v5/libpod" "github.com/containers/podman/v5/pkg/domain/entities" "github.com/containers/podman/v5/pkg/rootless" - "github.com/containers/podman/v5/utils" "github.com/docker/go-units" ) @@ -85,12 +84,7 @@ func combineBytesValues(a, b uint64) string { } func floatToPercentString(f float64) string { - strippedFloat, err := utils.RemoveScientificNotationFromFloat(f) - if err != nil || strippedFloat == 0 { - // If things go bazinga, return a safe value - return "--" - } - return fmt.Sprintf("%.2f", strippedFloat) + "%" + return fmt.Sprintf("%.2f%%", f) } func pidsToString(pid uint64) string { diff --git a/utils/utils.go b/utils/utils.go index bfca839140..9643fded8d 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -6,7 +6,6 @@ import ( "io" "os" "os/exec" - "strconv" "strings" "time" @@ -111,24 +110,6 @@ func TarWithChroot(source string) (io.ReadCloser, error) { return chrootarchive.Tar(source, nil, source) } -// 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, fmt.Errorf("unable to remove scientific number from calculations: %w", err) - } - return result, nil -} - // GuardedRemoveAll functions much like os.RemoveAll but // will not delete certain catastrophic paths. func GuardedRemoveAll(path string) error {