Results 1 to 3 of 3

Thread: Round to the nearest 50th

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2011
    Posts
    12

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2011
    Posts
    12

    Re: Round to the nearest 50th

    Alright. thx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width