Enhance FromHumanSize to parse float64 string#8
Conversation
Currently FromHumanSize can only interpret format of '32kB', this commit enhance it to interpret flat64 string with blank such as '32.3 kB'. Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
There was a problem hiding this comment.
FromHumanSize will always return int64 instead of float64, it will truncate float64 into int64. That's because in my opinion, 32.5 B isn't meaningful, user don't need to care bit, unit as Byte is already good enough.
I was thinking to produce error for 32.5 B and only support 32.5 KB or MB etc, but it will make regexp complicated, so I didn't do that.
There was a problem hiding this comment.
And there's some other situations, for example, 32.5634663 kB which is 32563.4663 B which is not meaningful, and it's hard to detect this format.
But I really need FromHumanSize to support parsing float64, because you know HumanSize will print 32.56 kB, I need this FromHumanSize to reverse the result.
So I think if we can't stop unmeaning input, we can still give meaningful output as some programming languages do.
|
LGTM |
|
@calavera Can we have another one's eye on this? So that we can move forward, my integration tests still count on it. Thank you 😄 |
|
Merging, thanks! |
Enhance FromHumanSize to parse float64 string
relevant changes: - docker/go-units#8 Enhance FromHumanSize to parse float64 string - docker/go-units#20 Add `HumanSizeWithPrecision` function Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
relevant changes: - docker/go-units#8 Enhance FromHumanSize to parse float64 string - docker/go-units#20 Add `HumanSizeWithPrecision` function Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
relevant changes: - docker/go-units#8 Enhance FromHumanSize to parse float64 string - docker/go-units#20 Add `HumanSizeWithPrecision` function Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
relevant changes: - docker/go-units#8 Enhance FromHumanSize to parse float64 string - docker/go-units#20 Add `HumanSizeWithPrecision` function Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
relevant changes: - docker/go-units#8 Enhance FromHumanSize to parse float64 string - docker/go-units#20 Add `HumanSizeWithPrecision` function Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
relevant changes: - docker/go-units#8 Enhance FromHumanSize to parse float64 string - docker/go-units#20 Add `HumanSizeWithPrecision` function Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
relevant changes: - docker/go-units#8 Enhance FromHumanSize to parse float64 string - docker/go-units#20 Add `HumanSizeWithPrecision` function Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
relevant changes: - docker/go-units#8 Enhance FromHumanSize to parse float64 string - docker/go-units#20 Add `HumanSizeWithPrecision` function Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
relevant changes: - docker/go-units#8 Enhance FromHumanSize to parse float64 string - docker/go-units#20 Add `HumanSizeWithPrecision` function Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
relevant changes: - docker/go-units#8 Enhance FromHumanSize to parse float64 string - docker/go-units#20 Add `HumanSizeWithPrecision` function Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
relevant changes: - docker/go-units#8 Enhance FromHumanSize to parse float64 string - docker/go-units#20 Add `HumanSizeWithPrecision` function Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Currently FromHumanSize can only interpret format of '32kB', this commit
enhance it to interpret float64 string with blank such as '32.3 kB'.
Signed-off-by: Zhang Wei zhangwei555@huawei.com
I need this function for doing
docker statsintegration test, becausedocker statsuseHumanSizeto format byte into human readable string, now I need to revert the string to byte number. ButFromHumanSizecan't interpret23.3 kB, so this commit add float64 support.I also add the blank support but it doesn't matter if you don't like it.
I think you may have special considerations for only supporting int64, but I'm not sure what's it.
I can make relevant change based on your ideas.
Ping @calavera