Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed scientific convention issue in image size #4459

Closed
wants to merge 2 commits into from

Conversation

Affan-7
Copy link

@Affan-7 Affan-7 commented Jul 22, 2023

This fixes #3091

In this code HumanSizeWithPrecision() method is used.

This method takes two parameters size and precision.

- Here is what I did:

I tried to reproduce the bug with this code.

package main

import (
	"fmt"

	"github.com/docker/go-units"
)

func main() {
	fmt.Println(units.HumanSizeWithPrecision(float64(999900000), 3))
}

And this resulted in 1e+03MB being output.

So I changed precision from 3 to 4 like the following.

package main

import (
	"fmt"

	"github.com/docker/go-units"
)

func main() {
	fmt.Println(units.HumanSizeWithPrecision(float64(999900000), 4))
}

And this gave me 999.9MB output.

In conclusion, this unexpected scientific convention results when we use precision 3.

In go-unit library the HumanSize() method uses HumanSizeWithPrecision(size, 4) method under the hood, So I used HumanSize() instead of using HumanSizeWithPrecision().

- Description for the changelog

Replaced HumanSizeWithPrecision() with HumanSize().

- A picture of a cute animal (not mandatory but encouraged)
An image of a cool looking cat

@codecov-commenter
Copy link

codecov-commenter commented Jul 22, 2023

Codecov Report

Merging #4459 (1d981e2) into master (8837d11) will not change coverage.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4459   +/-   ##
=======================================
  Coverage   59.39%   59.39%           
=======================================
  Files         288      288           
  Lines       24782    24782           
=======================================
  Hits        14720    14720           
  Misses       9175     9175           
  Partials      887      887           

@neersighted
Copy link
Member

Looks like this passes the existing tests, which is good. Can you please add a regression test (using your sample values from the PR body) to demonstrate the correctness of the fix/ensure we don't reintroduce it later?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Image size reported as 1e+03MB by docker image ls
3 participants