473,830 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

Thanks!
Mar 16 '06 #1
4 3657
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(My Number);

Hope this helps

Regards

Scott Blood
C# Developer

"Ryan Liu" <ad********@onl ine.sh.cn> wrote in message
news:e1******** *****@TK2MSFTNG P09.phx.gbl...
Is there a good reason that Decimal does not have Ceiling() method, only
Math class has?

Thanks!

Mar 16 '06 #2
scott blood wrote:
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(My Number);


Math.Ceiling(de cimal) 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).Cei ling();

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

Jon

Mar 16 '06 #3
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

"Jon Skeet [C# MVP]" <sk***@pobox.co m> ????
news:11******** **************@ e56g2000cwe.goo glegroups.com.. .
scott blood wrote:
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(My Number);


Math.Ceiling(de cimal) 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).Cei ling();

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

Jon

Mar 16 '06 #4
Ryan Liu wrote:
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

Mar 16 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
4545
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
5
28271
by: RichW | last post by:
Hi, I'm writing a program that has got a bit of maths in it. I perform a division and then end up with something like 2.50, or 3.87, or 4.9975 (ie. y.12345). I need to get rid of anything in front of the decimal point so that I'm just left with the bit after the decimal point, ie. 0.50, 0.87, 0.9975, 0.12345 for the examples above.
4
15383
by: vooose | last post by:
Consider a rounding up function: public static decimal RoundUp(decimal val, decimal round) { return ((decimal)Math.Ceiling((double)(val/round)))*round; } Math.Ceiling (and Math.Floor for RoundDown) only take double,s so we need to cast twice. Is there a better way?
5
23956
by: GaryB | last post by:
I have a database field that is the product of a multiply in a sql statement and it sometimes has 5 or more decimal places. I want to truncate beyond the 2nd decimal place(###.##). I figured a Ctype to a decimal value would do that but the four decimal places remain. I found a truncate function but it only truncates to whole numbers. how can I do the truncation? Thanks, G
1
1075
by: Ryan Liu | last post by:
Is there a good reason that Decimal does not have Ceiling() method, only Math class has? Thanks!
6
15822
by: Jon Vaughan | last post by:
Can someone tell me why the following statement gives me the result of 0 : Math.Ceiling( 1 / 12); Well actually the above is simplefied from : private const int LocationsPerPage = 12; (int)System.Math.Ceiling(dsLocations.Tables.Rows.Count / LocationsPerPage);
11
10017
by: ChrisM | last post by:
Hi Guys, I'm looking for a function that will return the lowest integer that is greater than or equal to a decimal number. eg. 3.1(decimal) returns 4(integer) 3.9(decimal) returns 4(integer) 4.0(decimal) returns 4(integer)
13
10564
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, Why does Math.Sqrt() only accept a double as a parameter? I would think it would be just as happy with a decimal (or int, or float, or ....). I can easily convert back and forth, but I am interested in what is going on behind the scenes and if there is some aspect of decimals that keep them from being used in this calculation. Thanks! Ethan Ethan Strauss Ph.D.
13
4419
by: =?Utf-8?B?THVpZ2k=?= | last post by:
Hi all, I need to round a decimal value with a particular rule. For example: decimal a = 1.49m -1m decimal a = 1.5m -1m decimal a = 1.51m -2m I've tried Math.Round but with the value 1.5 it returns me 2, which it is not correct for my business rule.
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10774
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10491
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10526
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10206
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9315
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7746
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5617
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.