Search All Articles Submit your Website or Blog to A New Internet Library
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);
}
}
Subscribe to:
Post Comments (Atom)
Also Read other Top Articles
- JSON Serialization in VS 2008
- Implementing Forms Authentication in Silverlight Application.
- Making GridView Rows or Individual Cells Clickable and Selectable.
- Enabling browser back button for GridView Paging and Sorting in Ajax 1.1 and 3.5 (using Visual Studio 2005/ Visual studio 2008)
- How to pass values from User Control to Page or calling Page methods from User Control.
- What is WCF?
- New features in C# 4.0
- C# to VB.NET and VB.NET to C# online free converter tools.


1 comments:
The above function i have tried it doesn't work
I have tried by making changes to it and it worked exactly like the Excel Ceiling
Public Function Ceiling(ByVal input As Double, ByVal ceilTo As Integer) As Integer
If (input Mod ceilTo) <> 0 Then
Return CInt(Math.Ceiling(input / ceilTo) * ceilTo)
Else
Return Convert.ToInt32(input)
End If
End Function
Post a Comment
Post your comments/questions/feedback for this Article.