## 3 replies

Last post Apr 24, 2013 09:27 AM by Bojjaiah Thoti

Member

8 Points

61 Posts

### math rounding question

I need number rounded down to the nearest whole number.

ex:

1.9 = 1

2.753 = 2

3.9=3

2.123364 = 2

How do I do this?

• BrockAllen

All-Star

20376 Points

6505 Posts

ASPInsiders

MVP

### Re: math rounding question

Math.Floor()

Brock Allen | http://brockallen.com
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
• Mr. Fluffels

Member

10 Points

1 Post

### Re: math rounding question

Apr 24, 2013 09:16 AM|Mr. Fluffels|LINK

• Math.Floor(); - Rounds Down.
• Math.Ceiling(); - Rounds Up.
• Math.Truncate(); - Rounds up or down towards zero.
• Math.Round(); - Rounds to the nearest integer or specified number of decimal places.

When you use Math.Round(); the value 2.5 will be rounded to 2.0. This is called Banker's rounding

```var value = 2.5;

var roundedDefault = Math.Round(value);
var roundedAwayFromZero = Math.Round(value, MidpointRounding.AwayFromZero);```

The value of roundedDefault will be 2.0.

The value of roundedAwayFromZero will be 3.0.

• Bojjaiah Tho...

Member

10 Points

13 Posts

### Re: math rounding question

Apr 24, 2013 09:27 AM|Bojjaiah Thoti|LINK

hi try this,

double k=1.9;

double results=Math.Round(k);