Question

I have a performance calculator, and that gives me the memory in KB. But i want to divide the Value with 1000, so I didnt get it longer in KB, but in MB.

I have tried this:

    progressBar9.Value = (int)(performanceCounter9.NextValue());
    progressBar9.Value.ToString() / 1000;
    textBox5.Text = "Max. memory: " + progressBar9.Value.ToString() + " KB";

I have never earlier calculated with C# so I am a little bit newbie with calculating in C#

Was it helpful?

Solution

Depending on what you want to show in your progressBar9 (KB or MB) you could use something like:

progressBar9.Value = (int)(performanceCounter9.NextValue()/1024); //value in MB

textBox5.Text = "Max. memory: " + progressBar9.Value.ToString() + " MB";

or

progressBar9.Value = (int)(performanceCounter9.NextValue()); //value in KB

textBox5.Text = "Max. memory: " + (progressBar9.Value/1024).ToString() + " MB";

OTHER TIPS

Use this

        pb.Value = (int)(pb.NextValue());
        decimal memory = Convert.ToDecimal(pb.Value) / 1024;
        textBox5.Text = "Max. memory: " + memory.ToString() + " KB";

Converting it to decimal will let your application be able to use decimals instead of just whole numbers.

There is also 1024 kb in a mb, not 1000.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top