Comment

Comment by ComputerGuru

Shameless plug: another option to format sizes in a human readable format quickly and correctly (other than copying from S/O), you can use one of our open source PrettySize libraries, available for rust [0] and .NET [1]. They also make performing type-safe logical operations on file sizes safe and easy!

The snippet from S/O may be four lines but these are much more extensive, come with tests, output formatting options, conversion between sizes, and more.

[0]: https://github.com/neosmart/prettysize-rs

[1]: https://github.com/neosmart/PrettySize.net

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton