473,782 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert Double to Int

double DesignGlassPric eDbl =WindowAreaSqFt Int * DesignGlassPric ePSF;
int DesignGlassPric eInt= System.ConvertT oInt32(DesignGl assPriceDbl);

In the above code, if "DesignGlassPri ceDbl" is 213.33, DesignGlassPric eInt
evaluates to 104, not 213.

How can I convert a double value to an Int? Dropping .33 in the process is
OK, but not dropping (for some reason inexplicable to me) 109.33.
Nov 16 '05 #1
4 47964
Worked fine for me (once I inserted a dot between Convert and ToInt32).
Framework 1.1 returned 213, as expected.

Apart from the obvious question (i.e., are you sure that DesignClassPric eDbl
actually equalled 213.33 in your test), what's different about your setup?

Tom Dacon
Dacon Software Consulting

"Stumped" <St*****@discus sions.microsoft .com> wrote in message
news:54******** *************** ***********@mic rosoft.com...
double DesignGlassPric eDbl =WindowAreaSqFt Int * DesignGlassPric ePSF;
int DesignGlassPric eInt= System.ConvertT oInt32(DesignGl assPriceDbl);

In the above code, if "DesignGlassPri ceDbl" is 213.33, DesignGlassPric eInt
evaluates to 104, not 213.

How can I convert a double value to an Int? Dropping .33 in the process is
OK, but not dropping (for some reason inexplicable to me) 109.33.

Nov 16 '05 #2
Stumped <St*****@discus sions.microsoft .com> wrote:
double DesignGlassPric eDbl =WindowAreaSqFt Int * DesignGlassPric ePSF;
int DesignGlassPric eInt= System.ConvertT oInt32(DesignGl assPriceDbl);

In the above code, if "DesignGlassPri ceDbl" is 213.33, DesignGlassPric eInt
evaluates to 104, not 213.

How can I convert a double value to an Int? Dropping .33 in the process is
OK, but not dropping (for some reason inexplicable to me) 109.33.


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

(I would also suggest just casting, rather than using Convert.ToInt32 ,
but that's a different matter.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
In my code prior to the first line show, I was mixing doubles and decimals,
so maybee "DesignGlassPri ceDbl" was not really a double.

Anyway, I ended the mixing by making all the variables doubles and now the
code works fine.

Appararently one should not mix variables like I did and not expect trouble?

Thanks for your offer!!

"Jon Skeet [C# MVP]" wrote:
Stumped <St*****@discus sions.microsoft .com> wrote:
double DesignGlassPric eDbl =WindowAreaSqFt Int * DesignGlassPric ePSF;
int DesignGlassPric eInt= System.ConvertT oInt32(DesignGl assPriceDbl);

In the above code, if "DesignGlassPri ceDbl" is 213.33, DesignGlassPric eInt
evaluates to 104, not 213.

How can I convert a double value to an Int? Dropping .33 in the process is
OK, but not dropping (for some reason inexplicable to me) 109.33.


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

(I would also suggest just casting, rather than using Convert.ToInt32 ,
but that's a different matter.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #4
Stumped <St*****@discus sions.microsoft .com> wrote:
In my code prior to the first line show, I was mixing doubles and decimals,
so maybee "DesignGlassPri ceDbl" was not really a double.

Anyway, I ended the mixing by making all the variables doubles and now the
code works fine.

Appararently one should not mix variables like I did and not expect trouble?


Well, it shouldn't make that kind of trouble at all - I'd still be
intrigued to see what produced those results. I'm glad it's all working
though :)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5

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

Similar topics

3
2316
by: jeff_zhang446 | last post by:
Hi, I try to convert double to string as below: std::string cnvrtToString(double lValue) { std::ostringstream lStream; lStream << lValue; return lStream.str();
12
16551
by: Alan | last post by:
how to convert double to short ? for example, I want to convert double doubleVal1 = 15000.1; double doubleVal2 = 12000.0; short shortVal; shortVal = doubleVal1 - doubleVal2; I want the result of shortVal = 3000 and store as short instead of double
2
4964
by: Pascal | last post by:
Why does this not work, and how should i do this convert in stead: string x = double.MinValue.ToString(); double y = Convert.ToDouble(x); i get this exception: An unhandled exception of type 'System.OverflowException' occurred in mscorlib.dll Additional information: Value was either too large or too small for a Double. Pascal
2
11528
by: paul gao via .NET 247 | last post by:
hi all. In my program I need to convert a double number to stringrepresentation in fraction format and vise versa. For example,convert 0.75 to string "3/4" and convert string "1/2" to 0.5.The class will only need to handle numbers that increment by1/32. That is 1/32, 2/32, 3/32.... 31/32, 1. If the doublenumber is 0.28 which is between 1/4 and 9/32, the string shouldbe 9/32(go with the bigger number). TIA --------------------------------...
4
9287
by: charliewest | last post by:
Hello - I am reading up on the NumberFormatInfo class, trying to figure out how to convert a double to a percentage, using the IFormatProvider. This seems a little beyond me. Can anyone suggest an easy way to convert a double to a percentage in C#? For example, i would like to render on my web page the following: ..89 = 89% 1 = 100%
5
36875
by: Steven | last post by:
I have tried to use FormatNumber() to convert a very large double type number to String format, however, the result seems not correct, is there any limitation for using FormatNumber() function? For example, I write the code shown below: Dim DblA as double = 999999999999999.12 Dim VarA As String = FormatNumber(DblA) The result of VarA contains value "999999999999999.00" instead of "999999999999999.12".
0
1183
by: aparna12 | last post by:
Hi all Please tell me how to Convert double to string in fraction format (.75 to 3/4) in asp.net. Thanks Aparna
1
16491
by: =?big5?B?qM6nuw==?= | last post by:
I already knew how to convert bytes to Double, use BitConverter.ToDouble(). but, How to convert double to bytes? for example: double a = 3,444; I want convert to bytes={ ?, ?, ?, ?, ?, ?, ?, ?}
21
7521
by: Aman JIANG | last post by:
hi I need to do this (convert double to string) fast, safe and portable. Is there any way to do this ? Except the ways following: 1. C++ I/O stream, stringstream (and boost::lexical_cast) 2. sprintf (and its brothers) 3. any nonstandard C/C++ functions
1
4080
by: Bjorn Brox | last post by:
Hi! In germany, norway and France(?) we are using ',' as decimal separator and it always messes up when you convert a double to and from a string where the interface expects double values stored as string is using '.' What parameter shall I use in double.ToString() to ensure that the outputstring always are using '.' as separator without thousand sep, and what parameter shall I use to convert double to Double.Parse() or...
0
9480
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
10313
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
9946
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
8968
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...
0
6735
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.