megabyte

Does .NET provide an easy way convert bytes to KB, MB, GB, etc.?

久未见 提交于 2019-12-17 03:50:43
问题 Just wondering if .NET provides a clean way to do this: int64 x = 1000000; string y = null; if (x / 1024 == 0) { y = x + " bytes"; } else if (x / (1024 * 1024) == 0) { y = string.Format("{0:n1} KB", x / 1024f); } etc... 回答1: Here is a fairly concise way to do this: static readonly string[] SizeSuffixes = { "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" }; static string SizeSuffix(Int64 value, int decimalPlaces = 1) { if (decimalPlaces < 0) { throw new ArgumentOutOfRangeException(

MySQL Convert Bytes to Kilobytes, Megabytes, Gigabytes

自作多情 提交于 2019-12-03 17:53:41
问题 I have a logs table that stores various file sizes in bytes. I want to be able to query the database and return the smallest possible float which has been converted to MB GB etc. At present I can return the value in MB but how do I continue to divide further to smallest value and append the unit? SELECT CONCAT( ROUND( SUM( data_transferred ) /1048576, 2 ) , ' MB' ) FROM `logs` Any help would be appreciated. UPDATE: Based on the link voodoo417 provided I updated my query to the following,

How to correctly convert filesize in bytes into mega or gigabytes?

拟墨画扇 提交于 2019-11-29 03:03:32
I'm using the DriveInfo class in my C# project to retrieve the available bytes on given drives. How to I correctly convert this number into Mega- or Gigabytes? Dividing by 1024 will not do the job I guess. The results always differ from those shown in the Windows-Explorer. Adam Davis 1024 is correct for usage in programs. The reason you may be having differences is likely due to differences in what driveinfo reports as "available space" and what windows considers available space. Note that only drive manufacturers use 1,000. Within windows and most programs the correct scaling is 1024. Also,

MySQL Convert Bytes to Kilobytes, Megabytes, Gigabytes

蹲街弑〆低调 提交于 2019-11-28 12:11:05
I have a logs table that stores various file sizes in bytes. I want to be able to query the database and return the smallest possible float which has been converted to MB GB etc. At present I can return the value in MB but how do I continue to divide further to smallest value and append the unit? SELECT CONCAT( ROUND( SUM( data_transferred ) /1048576, 2 ) , ' MB' ) FROM `logs` Any help would be appreciated. UPDATE: Based on the link voodoo417 provided I updated my query to the following, which will output the most relevant file size to two decimal places and append the unit (1000 Bytes, 1 KB,

How to correctly convert filesize in bytes into mega or gigabytes?

末鹿安然 提交于 2019-11-27 17:20:02
问题 I'm using the DriveInfo class in my C# project to retrieve the available bytes on given drives. How to I correctly convert this number into Mega- or Gigabytes? Dividing by 1024 will not do the job I guess. The results always differ from those shown in the Windows-Explorer. 回答1: 1024 is correct for usage in programs. The reason you may be having differences is likely due to differences in what driveinfo reports as "available space" and what windows considers available space. Note that only

Does .NET provide an easy way convert bytes to KB, MB, GB, etc.?

别等时光非礼了梦想. 提交于 2019-11-26 17:08:31
Just wondering if .NET provides a clean way to do this: int64 x = 1000000; string y = null; if (x / 1024 == 0) { y = x + " bytes"; } else if (x / (1024 * 1024) == 0) { y = string.Format("{0:n1} KB", x / 1024f); } etc... JLRishe Here is a fairly concise way to do this: static readonly string[] SizeSuffixes = { "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" }; static string SizeSuffix(Int64 value, int decimalPlaces = 1) { if (decimalPlaces < 0) { throw new ArgumentOutOfRangeException("decimalPlaces"); } if (value < 0) { return "-" + SizeSuffix(-value); } if (value == 0) { return string