using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Exferia_Actualizacion_BD.General { public class Funciones_Actualizacion_BD { public static string FormatBytes(long _lng_bytes, int _int_decimalPlaces, bool _bol_showByteType) { double dbl_newBytes = _lng_bytes; string str_formatString = "{0"; string str_byteType = "B"; // Check if best size in KB if (dbl_newBytes > 1024 && dbl_newBytes < 1048576) { dbl_newBytes /= 1024; str_byteType = "KB"; } else if (dbl_newBytes > 1048576 && dbl_newBytes < 1073741824) { // Check if best size in MB dbl_newBytes /= 1048576; str_byteType = "MB"; } else { // Best size in GB dbl_newBytes /= 1073741824; str_byteType = "GB"; } // Show decimals if (_int_decimalPlaces > 0) str_formatString += ":0."; // Add decimals for (int i = 0; i < _int_decimalPlaces; i++) str_formatString += "0"; // Close placeholder str_formatString += "}"; // Add byte type if (_bol_showByteType) str_formatString += str_byteType; return string.Format(str_formatString, dbl_newBytes); } } }