Humanizr / Humanizer

Humanizer meets all your .NET needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities
Other
8.59k stars 955 forks source link

Fix ByteSize implementation in regards to IEC specification #1413

Open CollinAlpert opened 6 months ago

CollinAlpert commented 6 months ago

This PR is targeted for the v3 release, since it contains a breaking change in how the ByteSize calculates sizes.

Until now, one kilobyte is considered to be 1024 bytes, which is incorrect. The code Console.WriteLine(ByteSize.FromMegabytes(1).Bytes); prints 1048576 instead of 1000000 which was initially very surprising to me. I have had countless discussions over this surprising behavior with my teammates.

This PR fixes the calculation and adds methods to aid in calculating binary instead of decimal powers.