• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

Vb.net/C# divide with Integer results

Hello folks, I've a little problem
I need to return integer result when I do a division like this:
37 / 10
What I need? this:
Ex1:
37 / 10 = 3
Ex2:
2 / 3 = 0

What I need to do to have results like that?

I prefer vb.net but if anyone can help me with C# is ok too.
Thanks for any help
0
nkoriginal
Asked:
nkoriginal
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Use the "backwards slash" to perform integer division.

See "\ Operator ": http://msdn.microsoft.com/en-us/library/0e16fywh(v=VS.80).aspx

    "Divides two numbers and returns an integer result."

So instead of "/" you use "\":

    x = 37 \ 10 ' <-- should give you 3
0
 
Gagan_JauraCommented:
Collect the result in integer data type. It will implicitly convert the division result to integer.
Or
You can use Math.Round(Decimal.parse(37)/10).
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now