Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Decimal Problem 1

Status
Not open for further replies.

BradB

MIS
Joined
Jun 21, 2001
Messages
237
Location
US
I'm trying to add two numbers together, and have problems with values less than 1.

Example
1 + 1 = 2
1.5 + 1.5 = 3
1.06 + 1.06 = 2.12
Problem
0.5 + 0.5 = 0.5

Here's the code I'm using:
'num1 = textbox
'num2 = textbox
'txtAmountOfTime = textbox

Private Sub cmd1Hour_Click()
num1 = 0.5
If txtAmountOfTime.Text = "" Then
txtAmountOfTime = 0.5
Else

num2.Text = txtAmountOfTime

If num1 And num2 <> &quot;&quot; Then
txtAmountOfTime.Text = Val(num1.Text) + Val(num2.Text)
End If
End If
End Sub
 
you got me...

im a bad, bad person [cry]

i was just tryin to cover my ass!!! [lol]



If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
To get the best response to a question, please check out FAQ222-2244 first
A General Guide To Excel in VB FAQ222-3383
 
Strongm,

Here's a reason for the differences in your iii).

When comparing the string to the boolean it must be converting to Boolean to do the comparison. Anything not 0 or &quot;false&quot; will convert to True when Converting to boolean.

When comparing the number to the boolean it must be converting to singles to do the comparison. When converting True to a numeric value it becomes -1. This doesn't match the 0.05 that it's being compared to.

-Sean
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top