Mick Dugan Posted December 31, 2004 Posted December 31, 2004 This seems like it shoud be so obvious, I'm almost ashamed to ask. I'm trying to cut off the remainder of a double by using CInt(valueOfDouble). Problem is, it's just rounding the number to the nearest integer instead of completely eliminating the remainder. Please set me straight so I can get on with the business of banging my head against the wall. Regards, Mike Quote
*Experts* mutant Posted January 1, 2005 *Experts* Posted January 1, 2005 You converting it to an integer, thats just the way it works, rounding the number would be the most logical thing to do during a conversion like that. Btw., you shouldn't use CInt but System.Convert.ToInt32() :), as CInt is an old function which shouldn't exist by now :). What you can do though is floor the number and convert it to an integer, or do the work yourself. Dim d as Double = 2.999999 Dim i as integer = Convert.ToInt32(Math.Floor(d)) Quote
Tygur Posted January 1, 2005 Posted January 1, 2005 Btw.' date=' you shouldn't use CInt but System.Convert.ToInt32() :), as CInt is an old function which shouldn't exist by now :).[/quote'] There is no reason to avoid CInt. In fact, CInt is better for performance as well as being much less to type, because it avoids a function call. Look here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vagrptypeconversion.asp It starts out by saying right in the beginning: These functions are compiled inline, meaning the conversion code is part of the code that evaluates the expression. Execution is faster because there is no call to a procedure to accomplish the conversion. Each function coerces an expression to a specific data type. Quote
Mick Dugan Posted January 1, 2005 Author Posted January 1, 2005 I had actually tried both conventions with the same results. I wasn't aware of putting math.floor in as part of the arguement though, I'll give it a try. Thanks for the responses guys. Regards, MD Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.