How do i round off a float(newbie)

  • Thread starter Thread starter jed
  • Start date Start date
i need to round off a float to two decimal places.

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
 
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);

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)

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);

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
 
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.
---------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top