Dup Ver Goto 📝

Human Friendly Humbers

To
19 lines, 63 words, 641 chars Page 'HumanFriendlyNumbers' does not exist.

Write humanised (aka human friendly) numbers. E.g. 1.5GB.

Use the humanize module:

python -m pip install humanize
# or
sudo apt-get install python3-humanize # ubuntu

This from this stackoverflow

import humanize

disk_sizes_list = [1, 100, 999, 1000,1024, 2000,2048, 3000, 9999, 10000, 2048000000, 9990000000, 9000000000000000000000]
for size in disk_sizes_list:
    natural_size = humanize.naturalsize(size)
    binary_size = humanize.naturalsize(size, binary=True)
    print(f" {natural_size} \t| {binary_size}\t|{size}")