D DeveloperX Mar 26, 2007 #2 i need to round off a float to two decimal places. Click to expand... result = System.Math.Round(value,precision)
i need to round off a float to two decimal places. Click to expand... result = System.Math.Round(value,precision)
R rossum Mar 26, 2007 #3 i need to round off a float to two decimal places. Click to expand... For display only, use the F2 format string: double test = 1.234567; Console.WriteLine("1) test = " + test.ToString("F2")); Console.WriteLine("2) test = {0:F2}", test); rossum
i need to round off a float to two decimal places. Click to expand... For display only, use the F2 format string: double test = 1.234567; Console.WriteLine("1) test = " + test.ToString("F2")); Console.WriteLine("2) test = {0:F2}", test); rossum
T Tim Sprout Mar 27, 2007 #4 For display only, use the F2 format string: double test = 1.234567; Console.WriteLine("1) test = " + test.ToString("F2")); Console.WriteLine("2) test = {0:F2}", test); Click to expand... The format strings round up if halfway between two numbers. Useful. The Math.Round method rounds to the even number if halfway between two numbers. Weird. -Tim Sprout
For display only, use the F2 format string: double test = 1.234567; Console.WriteLine("1) test = " + test.ToString("F2")); Console.WriteLine("2) test = {0:F2}", test); Click to expand... The format strings round up if halfway between two numbers. Useful. The Math.Round method rounds to the even number if halfway between two numbers. Weird. -Tim Sprout
T Tim Sprout Mar 27, 2007 #5 DeveloperX wrote: result = System.Math.Round(value,precision) Click to expand... For display only, use the F2 format string: double test = 1.234567; Console.WriteLine("1) test = " + test.ToString("F2")); Console.WriteLine("2) test = {0:F2}", test); Click to expand... The format strings round up if halfway between two numbers. Useful. The Math.Round method rounds to the even number if halfway between two numbers. Weird. -Tim Sprout
DeveloperX wrote: result = System.Math.Round(value,precision) Click to expand... For display only, use the F2 format string: double test = 1.234567; Console.WriteLine("1) test = " + test.ToString("F2")); Console.WriteLine("2) test = {0:F2}", test); Click to expand... The format strings round up if halfway between two numbers. Useful. The Math.Round method rounds to the even number if halfway between two numbers. Weird. -Tim Sprout
R RobinS Mar 27, 2007 #6 I think Math.Round always rounds to the even number. So if you have 23.5, it rounds to 24. If you have 24.5, it rounds to 24. I believe there is a third argument on the Round method for "midpoint rounding" argument where you can tell it what to do. Robin S. ---------------------------------
I think Math.Round always rounds to the even number. So if you have 23.5, it rounds to 24. If you have 24.5, it rounds to 24. I believe there is a third argument on the Round method for "midpoint rounding" argument where you can tell it what to do. Robin S. ---------------------------------
B Ben Voigt Mar 31, 2007 #7 Tim Sprout said: The format strings round up if halfway between two numbers. Useful. The Math.Round method rounds to the even number if halfway between two numbers. Weird. http://en.wikipedia.org/wiki/Rounding#Round-to-even_method -Tim Sprout Click to expand...
Tim Sprout said: The format strings round up if halfway between two numbers. Useful. The Math.Round method rounds to the even number if halfway between two numbers. Weird. http://en.wikipedia.org/wiki/Rounding#Round-to-even_method -Tim Sprout Click to expand...