interviews.dotnetthread.com

↑ Grab this Headline Animator

Friday, February 26, 2010

MS Excel like Ceiling function in c#.

- EXcel Ceiling function returns a number rounded up based on a multiple of significance.
- Example Ceiling(41.88, 10) will give 50 and Ceiling of 41.88 to 5 will give 45.
- Below is the C# function which gives the same result as Ceiling in MS Excel.



public int Ceiling(double input, int ceilTo)
{
if ((input % ceilTo) != 0)
{
return ((int)(input / ceilTo) * ceilTo) + ceilTo;
}
else
{
return Convert.ToInt32(input);
}
}

Submit this story to DotNetKicks

0 comments:

Post a Comment

Post your comments/questions/feedback for this Article.

 

Latest Articles