Drive Size calculated using decimal instead of binary

I have a WPF application that sits on the desktop and acts like a gadget.

It provides information to the user of the machine, one such piece of info is the current total drive size as collected from WMI.

It currently reports the drive size divided by 1024 3 times in order to get the size in GB, this results in the drive size that Windows itself reports.

I have been requested to provide the drive size in a manner similar to how drive manufacturers calculate it. (e.g. 1000MB is 1GB instead of 1024MB)

What I currently use is this;

 public string getdrive() { double disk = 0; ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_LogicalDisk where DeviceID='C:'"); foreach (ManagementObject wmi in searcher.Get()) { try { disk = Math.Round(((((double)Convert.ToDouble(wmi["Size"]) / 1024) / 1024) / 1024), 2); return disk.ToString() + " GB"; } catch { } } return "Unable to Find Drive"; } 

Is there any mouth that can be performed in order to essentially modify the calculation method?

by agent-squirrel via /r/csharp

Leave a Reply