Getting a value of 0 when dividing 2 lengths in C #

I am trying to separate the values โ€‹โ€‹of DriveInfo.AvailableFreeSpace and DriveInfo.TotalSize in order to try to get a percentage of it for use in the progress bar.

I need the final value to be int, since progressbar.value requires that int and the above methods return a long one.

I have this meaning:

164660715520 --- AvailableFreeSpace

256058060800 --- TotalSize

When I try to set the value of progressbar.value using this method, I also get the error message:

progressBar1.Value = (integer) (dInfo.AvailableFreeSpace / dInfo.TotalSize) * 100;

When I use this code to try to get the value, it just returns 0.

label10.Text =  (((int)dInfo.AvailableFreeSpace/dInfo.TotalSize)*100).ToString();

I even tried this and it does not work:

label10.Text = ((dInfo.AvailableFreeSpace/dInfo.TotalSize)*100).ToString();

, , , , , 0.

- long int?

+5
5

. , 3/5 0. . :

label10.Text =  (((int)((double)dInfo.AvailableFreeSpace/dInfo.TotalSize)*100)).ToString();
+12

dInfo.AvailableFreeSpace int , 164660715520, , 32 . 64 , .

, , , 100, .

100 ( ), :

label10.Text = ((100*dInfo.AvailableFreeSpace/dInfo.TotalSize)).ToString();

( 64).

long total = 256058060800L;
long avail = 164660715520L;
var pct = (100*avail/total).ToString();
Console.WriteLine("{0}", pct); // 64
+9

0, long , .

decimal 100

( , ProgressBar):

double someVariable = (double) longVariable1/(double) longVariable2;

:

public partial class Form1 : Form
{
   public Form1()
    {
         web.ProgressChanged += new WebBrowserProgressChangedEventHandler(web_ProgressChanged);
    }

private void web_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
    {

        <strong>double t = (100 * (double)e.CurrentProgress / (double)e.MaximumProgress);</strong>
        if (t < 0)
            return;
        int c = (int)t;
        progressBar.Value = c;

        if (c == 100)
        {
            label1.Text = "Done";                
        }
    }
}
+1

dInfo.AvailableFreeSpace dInfo.TotalSize ,

label10.Text = (((double)dInfo.AvailableFreeSpace/dInfo.TotalSize)*100).ToString();

+1

, , .

    private static double Improvement(string efficientTime, string inefficientTime)
    {
        var magnitude = Math.Pow(10, (inefficientTime.Length - efficientTime.Length));
        var time2 = (double) Convert.ToInt32(efficientTime.Substring(0, 5));
        var time1 = (double) Convert.ToInt32(inefficientTime.Substring(0, 5));
        var sigRatio = (time2 / time1);

        var sigPercent = sigRatio * magnitude;

        var improvement = sigPercent;
        return improvement;
    }
0

All Articles