/// <summary> /// Returns the file size as a descriptive string (12MB) /// </summary> public static string ToFileSize(this long bytes) { if (bytes == 0) { return("0 MB"); } string filesize = "MB"; int divisor; if (bytes >= 1073741824) { divisor = 1073741824; filesize = "GB"; } else if (bytes >= 1048576) { divisor = 1048576; } else if (bytes >= 1024) { divisor = 1024; filesize = "KB"; } else { return(string.Format("{0:##.##} bytes", bytes)); } return(string.Format("{0:##.##} {1}", Arithmetic.Divide(bytes, divisor), filesize)); }
/// <summary> /// Returns the the percentage of the number as a value of the specified value (dividend) rounded to the specified decimal point /// </summary> /// <param name="dividend">The number to divide by</param> /// <param name="round">Optional value round the result by</param> public static double DivideBy(this long d, double dividend, int?round = null) { return(Arithmetic.Divide(d, dividend, round)); }