ExUtils v0.1.6 ExUtils.Integer
Utility methods for the Integer
types
Summary
Functions
Formats an Integer
in a human-readable representation of filesize
This method returns a string representing filesize in Bytes (e.g giving
it 1250
returns "1.22 KB"
). It also accepts an optional value of
:precision
that formats the number to the given no. of decimal places
(default is 2
).
Example
ExUtils.Integer.to_filesize(12) # => "12 Bytes"
ExUtils.Integer.to_filesize(1234) # => "1.21 KB"
ExUtils.Integer.to_filesize(1234567) # => "1.18 MB"
ExUtils.Integer.to_filesize(1234567890) # => "1.15 GB"
ExUtils.Integer.to_filesize(1234567890123) # => "1.12 TB"
ExUtils.Integer.to_filesize(12345, precision: 1) # => "12.1 KB"
ExUtils.Integer.to_filesize(12345, precision: 2) # => "12.06 KB"
ExUtils.Integer.to_filesize(12345, precision: 3) # => "12.056 KB"