Ceiling / Floor vs. Roundup / Rounddown
difference between floor() and rounddown() function
Whats the difference between Round, Ceiling and Floor?
Whats the difference between Round, Ceiling and Floor?
Videos
John wrote:
I am looking for a single function that will do EITHER a ROUNDUP or ROUNDOWN based on the value. (i.e. on a scale from 1-10, if the value is 1-4, I want to round the value down; if value is 5-10, I want to round the value up). Is there such a function that will do this in a single calculation?
That's the very definition of ROUND. But your example is ambiguous insofar as it is unclear what digit you are talking about rounding.
If you want 1.4 in A1 to round to 1 and 1.5 to round to 2, use ROUND(A1,0).
If you want 14 to round to 10 and 15 to round to 20, use ROUND(A1,-1).
See the ROUND help page for more details.
PS: For future reference, when you have a question, start a new discussion instead of piggybacking an old discussion, much less a discusion marked "answer".
First, usually no two questions are every identical in all details. So your specifics might require a completely different direction.
Second, some helpful people might never see your new "response" because they do not look at discussions marked "answer".
Finally, since you are not the original poster, you have no way to mark responses to your question as "answer".
Hello. I am looking for a single function that will do EITHER a ROUNDUP or ROUNDOWN based on the value. (i.e. on a scale from 1-10, if the value is 1-4, I want to round the value down; if value is 5-10, I want to round the value up). Is there such a function that will do this in a single calculation? Thanks.
Here's a direct port of the Excel function for variable number of decimal places
public double RoundDown(double number, int decimalPlaces)
{
return Math.Floor(number * Math.Pow(10, decimalPlaces)) / Math.Pow(10, decimalPlaces);
}
e.g. RoundDown (13.608000,2) = 13.60, RoundDown(12345,-3) = 12000,
You could do the following:
var rounded = Math.Floor(13.608000 * 100) / 100;
Note that Math.Floor() rounds down to the nearest integer, hence the need to multiply, round down, and then divide.