Round to the nearest 50th
Hey, i have been looking around on the internet a lot but i could find any answers. Here's what i need. I have 4 variables. Xx, Yy, Xxx, and yyy(integers). Got that? Moving on. When i click on a form, i use this code
Code:
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
xx=e.x
yy=e.y
End If
End Sub
assumeing thats the right code to find the x and y values of where i'm clicking on the form, i want to round the xx and yy variables to the nearest 50th,whether its up or down, and then have them equal the xxx and yyy variables. Now, how do i do that? And it would be much appreciated if you explain it in a basic way.(optional) Ty
Re: Round to the nearest 50th
First up, never use variable names like that. Always use descriptive names unless the meaning is so obvious that a simple name will suffice. Xx and Xxx are definitely not obvious. If you need to use names like 'tempX' and 'finalX' or something like that then do so.
As for the question, you can easily round a value to any number of decimal places, so you should scale (multiply or divide) your value first, then round to the appropriate number of decimal places, then scale back again.
Re: Round to the nearest 50th