How can I check if the result is a fraction

How can I check if the result of dividing two numbers is a fraction in the visual base

here is what i need to do:

Dim x As Integer = 12 Dim y As Integer = 5 If TypeOf x/y Is fraction Then ( do something ) End If 

Thank you in advance

+4
source share
8 answers

Use a mod that will return the remainder of the division.

 Dim x As Integer = 12 Dim y As Integer = 5 If x Mod y > 0 Then MsgBox (x & " / " & y & " has a remainder, so it must be a fraction.") End If 
+2
source

Could you execute a module of two numbers, and then, if it is not zero, is it a fraction?

+5
source

Use the Mod statement to see that x is purely divisible by y:

 If x Mod y > 0 Then ' There will be a fraction. do something End If 
+2
source
 If x Mod y = 0 ' Not a fraction If x Mod y <> 0 ' Fraction 
+1
source

You can use the "Mod" operator and check if you can convert it to Integer ...

Mod statement (Visual Basic): http://msdn.microsoft.com/en-us/library/se0w9esz%28v=vs.100%29.aspx

+1
source

I assume that "Fraction" means "non-integer number", since any number can be represented as a fraction ...

One typical way is to use the module operator:

 If x MOD y <> 0 Then ' x/y is a fraction End If 
+1
source

The .NET Framework has a Math.DivRem , so if you really want to determine the dividend and balance at the same time:

 Dim x As Integer = 12 Dim y As Integer = 5 Dim r As Integer Dim d As Integer = Math.DivRem(x, y, r) If r <> 0 Then ( do something ) End If 
0
source

This solution is much better, O (1) constant

 If x Mod 1 = 0 Then ' Integer If x Mod 1 <> 0 Then ' Float 
0
source

All Articles