Example #1
0
        /// <summary>
        /// Formats a long to the highest binary prefix accourding to IEEE 1541 standard.
        /// http://en.wikipedia.org/wiki/IEEE_1541
        /// </summary>
        /// <example>The above code will give you:227,54 MiB
        /// <code>
        /// Util.Convert.BinaryPrefixes bp;
        /// string f = string.Format("{0} {1}", Util.Convert.FormatBytes(238594534, out bp), bp);
        /// </code>
        /// </example>
        /// <param name="bytes">double representation as bytes</param>
        /// <param name="decimals">Number of decimals the return data should have</param>
        /// <param name="bp">BinaryPrefix object that will show what prefix type returned data is of</param>
        /// <returns>formated bytes after conversion. Look at bp for prefix type</returns>
        public static double FormatBytes(double bytes, int decimals, out BinaryPrefixes bp)
        {
            bp = 0;
            while ((bytes / 1024d) > 1)
            {
                bytes /= 1024d;
                bp++;
            }
            Decimal des = new Decimal(bytes);

            bytes = Decimal.ToDouble(Decimal.Round(des, 2));
            return(bytes);
        }
Example #2
0
 /// <summary>
 /// Formats a long to the highest binary prefix accourding to IEEE 1541 standard.
 /// http://en.wikipedia.org/wiki/IEEE_1541
 /// </summary>
 /// <example>The above code will give you:227,54 MiB
 /// <code>
 /// Util.Convert.BinaryPrefixes bp;
 /// string f = string.Format("{0} {1}", Util.Convert.FormatBytes(238594534, out bp), bp);
 /// </code>
 /// </example>
 /// <param name="bytes">double representation as bytes</param>
 /// <param name="decimals">Number of decimals the return data should have</param>
 /// <param name="bp">BinaryPrefix object that will show what prefix type returned data is of</param>
 /// <returns>formated bytes after conversion. Look at bp for prefix type</returns>
 public static double FormatBytes(double bytes, int decimals, out BinaryPrefixes bp)
 {
     bp = 0;
     while ((bytes / 1024d) > 1)
     {
         bytes /= 1024d;
         bp++;
     }
     Decimal des = new Decimal(bytes);
     bytes = Decimal.ToDouble(Decimal.Round(des, 2));
     return bytes;
 }
Example #3
0
 /// <summary>
 /// Formats a long to the highest binary prefix accourding to IEEE 1541 standard.
 /// http://en.wikipedia.org/wiki/IEEE_1541
 /// </summary>
 /// <example>The above code will give you:227,54 MiB
 /// <code>
 /// Util.Convert.BinaryPrefixes bp;
 /// string f = string.Format("{0} {1}", Util.Convert.FormatBytes(238594534, out bp), bp);
 /// </code>
 /// </example>
 /// <param name="bytes">long representation as bytes</param>
 /// <param name="decimals">Number of decimals the return data should have</param>
 /// <param name="bp">BinaryPrefix object that will show what prefix type returned data is of</param>
 /// <returns>formated bytes after conversion. Look at bp for prefix type</returns>
 public static double FormatBytes(long bytes, int decimals, out BinaryPrefixes bp)
 {
     return FormatBytes((double)bytes, decimals, out bp);
 }
Example #4
0
 /// <summary>
 /// Formats a long to the highest binary prefix accourding to IEEE 1541 standard.
 /// http://en.wikipedia.org/wiki/IEEE_1541
 /// </summary>
 /// <example>The above code will give you:227,54 MiB
 /// <code>
 /// Util.Convert.BinaryPrefixes bp;
 /// string f = string.Format("{0} {1}", Util.Convert.FormatBytes(238594534, out bp), bp);
 /// </code>
 /// </example>
 /// <param name="bytes">double representation as bytes</param>
 /// <param name="bp">BinaryPrefix object that will show what prefix type returned data is of</param>
 /// <returns>formated bytes after conversion with 2 decimals. Look at bp for prefix type</returns>
 public static double FormatBytes(double bytes, out BinaryPrefixes bp)
 {
     return FormatBytes(bytes, 2, out bp);
 }
Example #5
0
 /// <summary>
 /// Formats a long to the highest binary prefix accourding to IEEE 1541 standard.
 /// http://en.wikipedia.org/wiki/IEEE_1541
 /// </summary>
 /// <example>The above code will give you:227,54 MiB
 /// <code>
 /// Util.Convert.BinaryPrefixes bp;
 /// string f = string.Format("{0} {1}", Util.Convert.FormatBytes(238594534, out bp), bp);
 /// </code>
 /// </example>
 /// <param name="bytes">long representation as bytes</param>
 /// <param name="decimals">Number of decimals the return data should have</param>
 /// <param name="bp">BinaryPrefix object that will show what prefix type returned data is of</param>
 /// <returns>formated bytes after conversion. Look at bp for prefix type</returns>
 public static double FormatBytes(long bytes, int decimals, out BinaryPrefixes bp)
 {
     return(FormatBytes((double)bytes, decimals, out bp));
 }
Example #6
0
 /// <summary>
 /// Formats a long to the highest binary prefix accourding to IEEE 1541 standard.
 /// http://en.wikipedia.org/wiki/IEEE_1541
 /// </summary>
 /// <example>The above code will give you:227,54 MiB
 /// <code>
 /// Util.Convert.BinaryPrefixes bp;
 /// string f = string.Format("{0} {1}", Util.Convert.FormatBytes(238594534, out bp), bp);
 /// </code>
 /// </example>
 /// <param name="bytes">double representation as bytes</param>
 /// <param name="bp">BinaryPrefix object that will show what prefix type returned data is of</param>
 /// <returns>formated bytes after conversion with 2 decimals. Look at bp for prefix type</returns>
 public static double FormatBytes(double bytes, out BinaryPrefixes bp)
 {
     return(FormatBytes(bytes, 2, out bp));
 }