Is there a good reason that Decimal does not have Ceiling() method, only Math class has?

  • Thread starter Thread starter Ryan Liu
  • Start date Start date
R

Ryan Liu

Is there a good reason that Decimal does not have Ceiling() method, only
Math class has?

Thanks!
 
Ryan,

AFAIK its in the maths class because it is a mathematical function. The
built in ceiling function dosn't actually work with decimal types only
double such as

double MyNumber = 1000.1;
MyNumber = Math.Ceiling(MyNumber);

Hope this helps

Regards

Scott Blood
C# Developer
 
scott said:
AFAIK its in the maths class because it is a mathematical function. The
built in ceiling function dosn't actually work with decimal types only
double such as

double MyNumber = 1000.1;
MyNumber = Math.Ceiling(MyNumber);

Math.Ceiling(decimal) arrived in .NET 2.0.

As for why it's a static method - it does mean that if you want to take
a ceiling of a float, you just need to do:

float f = ...;
f = (float) Math.Ceiling (f);
rather than:
f = (float) ((double)f).Ceiling();

Not sure that's a particularly good reason though...

Jon
 
Thanks, Jon and Scott .

Your code works fine. I was just curious why decimal has methods like
Floor(). Round(), Truncate() , just no Ceiling().

BTW, in Microsoft SDK for Decimal.Round, I think there is a tiny error in
doc,

For example, when rounded to two decimals, the value 2.345 becomes 2.34 [
should be 2.35 ] and the value 2.355 becomes 2.36.

Best Wishes,
Ryan
 
Ryan said:
Your code works fine. I was just curious why decimal has methods like
Floor(). Round(), Truncate() , just no Ceiling().

BTW, in Microsoft SDK for Decimal.Round, I think there is a tiny error in
doc,

For example, when rounded to two decimals, the value 2.345 becomes 2.34 [
should be 2.35 ] and the value 2.355 becomes 2.36.

No, it should be 2.34, because Math.Round uses Banker's Rounding. Try
it - you'll get 2.34.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top