title: Excel VBA - Userform textbox formatting causing rounding errors
body: <p>I have a user form with 3 text fileds. <code>txtCurrentSum</code>, <code>txtTargetVal</code> and <code>txtDelta</code>. I've initialized textbox values when the form opened.</p>
  
  <p><code>delta</code> should be zero, but the <code>txtDelta</code> textbox is showing <code>4,99999999999545E-03</code></p>
  
  <p>How can I circumvent this stiuation?</p>
  
  <pre><code>'Variable Definitions
  Private originalSum As Double
  Private targetSum As Double
  Private precision As Integer
  Private delta As Double
  
  Private Sub UserForm_Initialize()
  
      originalSum = 311.135
      targetSum = originalSum
      delta = targetSum - originalSum
  
      precision = 2      
      txtCurrentSum.Text = Format(Hammer.originalSum, "#,##0.00")
      txtTargetVal.Text = Format(targetSum, "#,##0.00")
      txtDelta.Text = Format(delta, "#,##0.00")
  
  End Sub
  </code></pre>
  
  <p>I didn't set number formatting in the form's objectView/Properties because I'll change them programmaticaly.</p>
  
  <hr>
  
  <p>Found the problem in other subroutine. Apparently <code>Sub txtTargetVal_AfterUpdate()</code> event is triggering when I initialize the textboxes. <code>delta</code> was updated in this sub. I add <code>round</code> here to fix the problem.</p>
  
  <pre><code>' Target Value Changed
  '
  Private Sub txtTargetVal_AfterUpdate()
      targetSum = CDbl(txtTargetVal.Text)
      txtDelta.Text = targetSum - originalSum
  End Sub
  </code></pre>
  
  <p>Here I changed <code>txtDelta.Text = targetSum - originalSum</code> with <code>txtDelta.Text = Round(targetSum - originalSum, precision)</code></p>