Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted
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.

Posted

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

Posted
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.

Posted

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

Posted
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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...