title: Converting an objects x/y value into an int
body: <p>I have a simply block of code, that when you mouse up, it snaps an object to the nearest 30/30 grid.</p>
  <pre><code>private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
  {
      int gridCubeWidth = 30;
      int gridCubeHeight = 30;
  
      if (e.Button == System.Windows.Forms.MouseButtons.Left)
      {                                       
          double newX = Math.Round(pictureBox1.Left / (double)gridCubeWidth) * 
              (double)gridCubeWidth;
  
          pictureBox1.Left = (int)newX;
  
          double newY = Math.Round(pictureBox1.Top / (double)gridCubeHeight) * 
              (double)gridCubeHeight;
  
          pictureBox1.Top = (int)newY;
      }
  }
  </code></pre>
  <p>This is the only way I managed to get this to work, because from what I can tell, pictureBox1.left/top are in the form of &quot;Doubles&quot;, which breaks my Math.Round.</p>
  <p>I've tried changing everything to be Int, and adding (Int) in front of the pictureBox1.Left, but it doesn't seem to change this.</p>
  <pre><code>int newX = Math.Round((int)pictureBox1.Left / gridCubeWidth) * gridCubeWidth;
  pictureBox1.Left = newX;
  </code></pre>
  <p>I feel like what I'm doing is somewhat very redundant, converting everything to Doubles, then back to an Int, and that there'd be a much simpler way to achieve this.</p>
  <p>My main question, is why doesn't <code>(int)pictureBox1.Left</code> seem to convert this value into an Int</p>