By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,646 Members | 2,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,646 IT Pros & Developers. It's quick & easy.

weird integer rounding error

P: 1
hi guys why does this

Dim x As Integer
Dim y As Double

y = 4.664
x = Convert.ToInt32(y)

give me x=5 ?????

surely it should be 4

it doesnt matter what conversion i do all my integers round up if above .5 and down if below .5

any ideas ? ? ? ?
Nov 27 '07 #1
Share this Question
Share on Google+
2 Replies

Mohan Krishna
P: 115
any ideas ? ? ? ?

Why don't u use INT()?

Nov 27 '07 #2

Expert 5K+
P: 8,434
What this code is doing is rounding. From the sound of it, you don't want rounding, you want truncation. As Mohan mentioned, the Int() function may be the way to go. (This applies to VB6 - not sure about your version.)
Nov 27 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.