docker/go-units

HumanSizeWithPrecision uses scientific notation in some invalid cases

kmirzavaziri opened this issue · 1 comments

Let's keep it short, such a test will fail:

assertEquals(t, "1GB", HumanSizeWithPrecision(999.6*MB, 3))

With the following message:

Expected '1GB' but got '1e+03MB'

The case holds in the following scenarios:

  • any 999.5 <= x < 1000 for any unit including bytes, kB, MB, GB, etc. (with precision 1, 2, or 3)
  • any 99.5 <= x < 1000 for any unit including bytes, kB, MB, GB, etc. (with precision 1 or 2)
  • any 9.5 <= x < 1000 for any unit including bytes, kB, MB, GB, etc. (with precision 1)

However, it works fine with precision 4 or higher.

I am willing to fix this issue as a new person to open source contribution.