473,588 Members | 2,574 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to convert from Double to Int32

Bob
System.Convert. ToInt32() doesn't work the way that I want, as the function
rounds the double value to the nearest 32-bit integer. For example, for a
number 11.75, it returns 12, but I want 11 (the floor). Is there a function
in .NET to do this?


Jul 21 '05 #1
1 1312
"Bob" <bo******@yahoo .com> wrote in
news:Oa******** ******@TK2MSFTN GP10.phx.gbl:
System.Convert. ToInt32() doesn't work the way that I want, as the
function rounds the double value to the nearest 32-bit integer. For
example, for a number 11.75, it returns 12, but I want 11 (the floor).
Is there a function in .NET to do this?


The class System.Math has a static Floor method. The floor method takes
and returns a double, so you have to cast it to integer afterwards.

double myDouble = 11.75;
int myInt = (int)Math.Floor (myDouble);

Michael Lang
Jul 21 '05 #2

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

Similar topics

6
15024
by: Jeff Reed | last post by:
Doing something like this (cast) doesn't work. Y.value = (Int32)stringvariable; I get this message: Cannot convert type 'string' to 'int' Any idea how I can convert string to Int32? thxs
8
3831
by: Sachi | last post by:
Hi, Can anyone convert for me this Vb.bet code into C#? I am trying to convert example a sample from MSDN article. Static types() As Type = {GetType(String), GetType(Byte), _ GetType(Int16), GetType(Int32), GetType(Int64), GetType(Single), _ GetType(Double), GetType(Decimal), GetType
3
10266
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function and there you have it. So I enquired and found the Convert class with it's promising ToInt32 method, great... but it doesn't work. The thing keeps throwing Format Exceptions all over the place. What is the "C#" way to do this??? code int wmin,...
2
29489
by: jiangyh | last post by:
hi there : I have a question about how to convert Type to DbType? thanks a lot. jiangyh
4
11027
by: Daniel Walzenbach | last post by:
Hi, I wonder if somebody could explain me the difference between Double.Parse and Convert.ToDouble. If I'm not mistaken they are implemented differently (I though for a moment they might be the same like cint(anInt) and cType(anInt, System.Int32) but I checked with ildasm) - if I didn't made a mistake. So when to use which syntax? Is there any performance penalty when using the one over the other or does anybody knows any differences? '...
3
2247
by: Eric BOUXIROT | last post by:
hi, i must convert all of these eVC++ prototypes to use with VB.NET.... DLLEXPORT long F_BDO_MessageBoxOK(char *IN_title, char *IN_msg ); DLLEXPORT long F_BDO_MessageBoxOUINON(char *IN_title, char *IN_msg ); DLLEXPORT long F_BDO_CalculAXplusB(short int *IN_Tab_entree ,int IN_taille , double *OUT_Tab_sortie_freq , double *OUT_Tab_sortie, double IN_A,
1
300
by: Bob | last post by:
System.Convert.ToInt32() doesn't work the way that I want, as the function rounds the double value to the nearest 32-bit integer. For example, for a number 11.75, it returns 12, but I want 11 (the floor). Is there a function in .NET to do this?
3
8730
by: mrajanikrishna | last post by:
Hi Friends, I am accepting a number from the user entered in a textbox. I want to assign to a variable in my code and assignt this to that variable. double num1 = (double)txtNum1.text; this produced an error
9
12087
by: =?Utf-8?B?Qnlyb24=?= | last post by:
How do you convert a hex string into a double using C# in framework v2.0? I've seen this question answered before, but apparently something has changed in 2.0 that negates the old solution that I've seen. The code: DoubleVariable = Double.Parse(HexString, NumberStyles.AllowHexSpecifier); results in the error: "The number style AllowHexSpecifier is not supported on floating point data
0
7857
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
8220
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...
1
7981
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
8222
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...
1
5723
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
5396
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
3846
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...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1194
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.