Decimal Problem

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

If Texthold = 2.
and TxtHold2 = 3.
TxtDisplay should Equal 6.
But I get 6
The decimal gets dropped, does anyone know why?
Thanks
DS

Me.TxtDisplay = CDbl(Me.TxtHold) + CDbl(Me.TxtHold2)
 
Try formatting the 3 fields with
#\.
The \ forces the period to be a "literal" character.
 
Al said:
Try formatting the 3 fields with
#\.
The \ forces the period to be a "literal" character.
This #\. seems to work but another problem comes up....it starts
rounding weird like. 2.25 + .5 become 3.
it should be 2.75.....the beat goes on :)

Sometimes I have decimaled numbers sometimes not, is there a way to get
this thing to calculate properly? Heres some more snipites of code. I
have a number pad form 0 to 9 and a key for adding, dividing,
multiplying and subtracting. also an equal key and finally a decimal key.

The code behind the equal key...
Private Sub CommandEqual_Click()
Me.TxtHold2 = Me.TxtDisplay
Select Case Me.TxtOperator
Case 1
Me.TxtDisplay = CDbl(Me.TxtHold) + CDbl(Me.TxtHold2)
Case 2
Me.TxtDisplay = CDbl(Me.TxtHold) / CDbl(Me.TxtHold2)
Case 3
Me.TxtDisplay = CDbl(Me.TxtHold) - CDbl(Me.TxtHold2)
Case 4
Me.TxtDisplay = CDbl(Me.TxtHold) * CDbl(Me.TxtHold2)
End Select
End Sub


Code behind an add, multiply, divide, minus key...
Private Sub CommandDivide_Click()
Me.TxtOperator = 2
Me.TxtHold = Me.TxtDisplay
Me.TxtDisplay = ""
End Sub


Code behind a number key...
Private Sub Command6_Click()
Me.TxtDisplay = Me.TxtDisplay & 6
End Sub

This all basically works...the only problem is the decimal and the
rounding.....any input appreciated.
Thanks
DS
 
Back
Top