# Math Round • ### Question

• User1077474044 posted

I am trying to use Math.round

now my math.round (2.5) converting it to 2

O want to convert it to 3

Let me know how this is possible

Friday, May 8, 2009 11:28 AM

• User1330954201 posted

double d = Math.Round(2.5, MidpointRounding.AwayFromZero);

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Friday, May 8, 2009 12:27 PM

### All replies

• User-1171043462 posted

try this use Math.Ceiling

Dim no As Double = 2.5

Dim no2 As Integer = Convert.ToInt32(Math.Ceiling(no))

Friday, May 8, 2009 12:16 PM
• User1330954201 posted

double d = Math.Round(2.5, MidpointRounding.AwayFromZero);

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Friday, May 8, 2009 12:27 PM
• User1077474044 posted

Thanks you both

Friday, May 8, 2009 12:40 PM
• User-1559148285 posted

Thanks it helped me [Yes]

Wednesday, June 3, 2009 3:10 PM
• User-974554290 posted

or use this function

myRound(2.5)

public static Double myRound(Double Value, int places = 1000)
{
Double myvalue = (Double)Value;
if (places == 1000)
{
if (myvalue - (int)myvalue == 0.5)
{
myvalue = myvalue + 0.1;
return (Double)Math.Round(myvalue);
}
return (Double)Math.Round(myvalue);
places = myvalue.ToString().Substring(myvalue.ToString().IndexOf(".") + 1).Length - 1;
} if ((myvalue * Math.Pow(10, places)) - (int)(myvalue * Math.Pow(10, places)) > 0.49)
{
myvalue = (myvalue * Math.Pow(10, places + 1)) + 1;
myvalue = (myvalue / Math.Pow(10, places + 1));
}
return (Double)Math.Round(myvalue, places);
}

Monday, January 17, 2011 3:11 AM
• User-1460485343 posted

Math round function only rounds the value, complete tutorial on math.round function is available at:

http://www.bitsbyta.blogspot.com/search?q=math+round&x=0&y=0

Instead of round function use other function from math library like ceiling.

Complete list of math functions available on:

http://www.bitsbyta.blogspot.com/

If you have query then reply

Wednesday, February 9, 2011 5:50 AM