Commits

Iñigo Serna committed bbd8953

irex: MyUtils: new format_size()

  • Participants
  • Parent commits 8a7d011

Comments (0)

Files changed (1)

File irex/MyUtils.vapi

         public int isdst;
     }
 
-
     [CCode (cheader_filename = "time.h", cname = "gmtime_r")]
     static void gmtime_r (ref time_t time, out tm result);
     [CCode (cheader_filename = "time.h", cname = "localtime_r")]
         tm now = now2tm();
         return tm2strftime(ref now, format);
     }
+
+
+	public string format_size(int64 size, string sep=" ") {
+		if (size >= 1000000000)
+			return "%.2f%sGB".printf(size/(1024*1024*1024.0), sep);
+		else if (size >= 1000000)
+			return "%.2f%sMB".printf(size/(1024*1024.0), sep);
+		else if (size >= 1000)
+			return "%.2f%sKB".printf(size/1024.0, sep);
+		else
+			return "%lld%sB".printf(size, sep);
+	}
 }