lib/rest-ftp-daemon/helpers.rb in rest-ftp-daemon-0.221 vs lib/rest-ftp-daemon/helpers.rb in rest-ftp-daemon-0.221.1

- old
+ new

@@ -6,16 +6,18 @@ config[:users] = Settings.users.keys if Settings.users config[:endpoints] = Settings.endpoints.keys if Settings.endpoints config end - def self.format_bytes number, unit="" + def self.format_bytes number, unit="", decimals = 0 return "Ø" if number.nil? || number.to_f.zero? units = ["", "k", "M", "G", "T", "P" ] index = ( Math.log( number ) / Math.log( 2 ) ).to_i / 10 - converted = number.to_i / ( 1024 ** index ) - "#{converted} #{units[index]}#{unit}" + converted = number.to_f / ( 1024 ** index ) + + truncated = converted.round(decimals) + "#{truncated} #{units[index]}#{unit}" end def self.text_or_empty text return "-" if text.nil? || text.empty? # return "Ø" if text.nil? || text.empty?