How can I round this Convert.ToInt64 number that will be returned.

netman06

New member
Joined
Jun 22, 2012
Messages
1
Programming Experience
1-3
Hello,

I need to have this number rounded and have never done this before, so If you can help me that would be great.

long mem1 = Convert.ToInt64(objPartition["Size"].ToString()) / 1024 / 1024 / 1024 + 0;

Currently it is reporting 3GB and should be 4GB

So this number must be close to 3.xxxx and need to be round up to 4.xx

I found this on msdn, but dont understand how to make it work with my line of code.

Math.Round(3.44, 1); //Returns 3.4.
Math.Round(3.45, 1); //Returns 3.4.
Math.Round(3.46, 1); //Returns 3.5.

Thanks for your help,

-Mike
 
double partitionsize = // whatever the objPartition size isdouble mem1 = partitionsize/ 1024 / 1024 / 1024;
double mem2 = Math.Round(mem1, 2);

The second argument of the Math.Round method is the number of places after the decimal point. With only 1 argument, it will round out to the nearest whole number.

Note: You are attempting to do a math computation using a string. The string should first be converted into a number before placing it into the equation. Also, by declaring your variables as long, you are doing integer division instead of regular division. Change them to double.
 
Last edited:

Latest posts

Back
Top