Filesize To String

I’ve made a simple function that converts a file size to a string. It computes the remainder after dividing the input size by 1024 and puts it in an array. This step is being performed while we have a size under 1024 – this is the number of the bytes.

The type of size is Int64. It allows you to calculate too big numbers. After filling up the array, you can start walking it from its end like this:

Calling this function with argument Int64.MaxValue gives you the following result:

7EB 1023PB 1023TB 1023GB 1023MB 1023KB 1023bytes(s)