PC Review


Reply
Thread Tools Rate Thread

decimal - int

 
 
=?Utf-8?B?RGF2ZQ==?=
Guest
Posts: n/a
 
      21st Mar 2005
How do I convert a decimal number to an integer.
 
Reply With Quote
 
 
 
 
Morten Wennevik
Guest
Posts: n/a
 
      21st Mar 2005
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 <(E-Mail Removed)>
wrote:

> How do I convert a decimal number to an integer.




--
Happy Coding!
Morten Wennevik [C# MVP]
 
Reply With Quote
 
John Bailo
Guest
Posts: n/a
 
      21st Mar 2005
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
> <(E-Mail Removed)> wrote:
>
>> How do I convert a decimal number to an integer.

>
>
>
>

 
Reply With Quote
 
Bruce Wood
Guest
Posts: n/a
 
      21st Mar 2005
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text box formatted to General Number with 2 decimal places NOTallowing the decimal place. p-rat Microsoft Access Form Coding 3 14th Jan 2008 05:20 PM
Make decimal work properly in fixed decimal entry in Excel 2003. =?Utf-8?B?am9obmdpaWk=?= Microsoft Excel Crashes 0 12th Apr 2006 06:05 AM
Converting 2-place decimal value to floating point decimal number with leading zero Kermit Piper Microsoft Excel Misc 3 18th Mar 2006 06:20 PM
Repost: Decimal division/remainder fail near Decimal.MaxValue =?Utf-8?B?S2VpdGggRG9ya2Vu?= Microsoft Dot NET Framework 0 22nd Oct 2004 07:33 PM
Decimal class now preserves trailing zeroes after the decimal point Uncle Goh Microsoft Dot NET Framework 0 11th Sep 2003 09:15 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:30 PM.