473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

decimal - int

How do I convert a decimal number to an integer.
Nov 16 '05 #1
3 3670
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
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
4
by: Julian Hernandez Gomez | last post by:
Hi ! This is maybe a silly question, but... is there a "easy way" to make eval() convert all floating numbers to Decimal objects and return a Decimal? for example: ...
11
by: Timothy Smith | last post by:
i want to trunkate 199.999 to 199.99 getcontext.prec = 2 isn't what i'm after either, all that does is E's the value. do i really have to use floats to do this?
17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
2
by: Carl G | last post by:
I am storing a 0.000 a System.Decimal in a DataRow. On retrieval the value is only 0 without the three decimal places. It looks like the Get property returns System.Decimal.Zero, but why???? I...
2
by: Steve Summit | last post by:
-----BEGIN PGP SIGNED MESSAGE----- It's often explained that the reason for some of the imprecision in C's definition is so that C can be implemented on different kinds of machines -- say, those...
8
by: nick | last post by:
printf("%lf",3.25); the result is 3.25000 i want the answer correct to 3 decimal places What should i do? thanks!
10
by: Paul Sullivan | last post by:
decimal d; d = 1.1M OR d= (decimal) 1.1 Discussioon
8
by: Gilbert Fine | last post by:
This is a very strange exception raised from somewhere in our program. I have no idea how this happen. And don't know how to reproduce. It just occurs from time to time. Can anyone give me some...
25
by: Lennart Benschop | last post by:
Python has had the Decimal data type for some time now. The Decimal data type is ideal for financial calculations. Using this data type would be more intuitive to computer novices than float as its...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.