I'm sure some of you know the equation to get the distance of 2 points on a coordinate grid, and I'm making a program to do just that, the only problem is that when I use the square root function it doesn't return an exact number, what's wrong with my code?
vb Code:
Dim P1 As Integer = CInt(X2.Text) - CInt(X1.Text) Dim P2 As Integer = CInt(Y2.Text) - CInt(Y1.Text) Dim XX1 As Integer = P1 * P1 Dim YY1 As Integer = P2 * P2 Dim W1 As Integer = XX1 + YY1 Dim Sq As Integer = System.Math.Sqrt(W1) Sol.Text = Sq
I don't get why it automatically rounds the number up. Can anyone tell me how to code it to get an exact square root?




Reply With Quote