Possible Duplicate:
Round a double to 2 significant figures after decimal point
I have a value var i = 0.69999980926513672
. I need to round this value to 0.7
is there a built-in method that will do this?
Possible Duplicate:
Round a double to 2 significant figures after decimal point
I have a value var i = 0.69999980926513672
. I need to round this value to 0.7
is there a built-in method that will do this?
Use one of:
System.Math.Round (i, 1, MidpointRounding.ToEven);
System.Math.Round (i, 1, MidpointRounding.AwayFromZero);
The difference is how it handles numbers that are equidistant to the rounding point (e.g., 0.65 in your case could either go to 0.7 or 0.6).
Here is a answer I gave to another question which holds much more information.
You are looking for the Math.Round
method.
//first param is number to round
//second param is the accuracy to use in the rounding (number of decimal places)
Math.Round(i, 2)
Console.WriteLine(System.Math.Round(0.69999980926513672d, 1));
-- edit
wow, you blink and there are 5 other answers!
Use the Math.Round method:
double i = 0.69999980926513672;
double result = Math.Round(i, 2);