zubie Posted August 4, 2004 Posted August 4, 2004 Hi All In vb.net 8 mod 5 returns 3 (the remainder) The calc I require is one that returns the 1 my code at the moment returns 2 on the above calc. intBonus = cint(8/5) Can anyone help here? cheers ZuBiE Quote
AFterlife Posted August 4, 2004 Posted August 4, 2004 Hi All In vb.net 8 mod 5 returns 3 (the remainder) The calc I require is one that returns the 1 my code at the moment returns 2 on the above calc. intBonus = cint(8/5) Can anyone help here? cheers ZuBiE I would use the built in Math.Floor() function to truncate. To go to the next highest it would be Math.Ceiling() So something like intBonus=Math.Floor(intBonus) Should do the trick. Quote
Administrators PlausiblyDamp Posted August 4, 2004 Administrators Posted August 4, 2004 try something like intbonus = Convert.ToInt32(Math.Floor(8 / 5)) not tested though so use at your own risk ;) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
zubie Posted August 4, 2004 Author Posted August 4, 2004 I looked up truncate in the help (vb.net) and all I got was Int and Fix. Both these round the number up and down I only want to round down Quote
AFterlife Posted August 4, 2004 Posted August 4, 2004 I looked up truncate in the help (vb.net) and all I got was Int and Fix. Both these round the number up and down I only want to round down That's what the Math.Floor() function does. Quote
zubie Posted August 4, 2004 Author Posted August 4, 2004 Excellent .. thats exactly what I was looking for .. cheers ZuBiE Quote
mskeel Posted August 4, 2004 Posted August 4, 2004 You could also do integer division in VB.net and have it work as it does in c++ -- truncating any decimal parts. This is EXTREMEly intuitive, so watch out... use the backslash to divide. \. So... 8 / 5 = 1.6 8 \ 5 = 1 Quote
cyclonebri Posted August 4, 2004 Posted August 4, 2004 You could also do integer division in VB.net and have it work as it does in c++ -- truncating any decimal parts. This is EXTREMEly intuitive, so watch out... use the backslash to divide. \. So... 8 / 5 = 1.6 8 \ 5 = 1 That's cool..I didn't even know you could do that in VB.net 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.