module StatisticsHelper include AttachmentsHelper def data_format_string num result = num if num < 1 result = format("%0.1f", (num*1024)).to_s + " KB" elsif num < 1024 result = format("%0.1f", num).to_s + " MB" elsif num < 1024 * 1024 result = format("%0.1f", (num/1024)).to_s + " GB" else result = format("%0.1f", (num/(1024*1024))).to_s + " TB" end source = result.split(".") source[0] = source[0].gsub(/(\d)(?=(\d{3})+(?!\d))/, "\\1,") return source.join(".") end # excel中的数据大小转换成MB def file_size_revert size_str result = 0 unit = size_str[-2, 2] if unit == "GB" result = size_str.to_f * 1024 elsif unit == "KB" result = (size_str.to_f / 1024).round(3) else result = size_str.to_f end result end end