By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,559 Members | 1,150 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,559 IT Pros & Developers. It's quick & easy.

decimal - int

P: n/a
How do I convert a decimal number to an integer.
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Dave,

You cast it to int

decimal d = 10;
int i = (int)d;

Another method would be

int i = Convert.ToInt32(d);

On Mon, 21 Mar 2005 06:17:15 -0800, Dave <Da**@discussions.microsoft.com>
wrote:
How do I convert a decimal number to an integer.


--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2

P: n/a
Morten Wennevik wrote:
Hi Dave,

You cast it to int

decimal d = 10;
int i = (int)d;

Another method would be

int i = Convert.ToInt32(d);

And, also, Int32.Parse()

On Mon, 21 Mar 2005 06:17:15 -0800, Dave
<Da**@discussions.microsoft.com> wrote:
How do I convert a decimal number to an integer.


Nov 16 '05 #3

P: n/a
Int32.Parse() converts a string to an int, not a decimal to an int.

Depending upon how you want to perform the conversion, you might also
want to look at Math.Ceiling and Math.Round. For example:

Decimal d = 5.56;
int i = (int)Math.Round(d);
int j = (int)d;

After this code, i will contain the value 6, while j will contain the
value 5.

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.