Android Question multiplying doubles and long

ViMeAv ICT

Member
Licensed User
Longtime User
Dim nVal As Long
Dim nPrice As Double

nPrice = 8.95
nVal = nPrice * 100

nVal returns 894.

How is this possible?
If I use 2.95, it's okay. (or all other numbers I have tested until now)
 
I've been through it many times. In a accounting calculation program I realized I had many problems for this error.

Now I pass the double in the string and shift the decimal decimal point with the string to not have any calculation errors.
 
Upvote 0
Code:
Dim nVal As Long
Dim nPrice As Double
Dim S as string

nPrice = 8.95
S=nPrice
nVal = S.Replace(".","")
 
Upvote 0
Dim nVal As Long
Dim nPrice As Double

nPrice = 8.95
nVal = nPrice * 100

nVal returns 894.

How is this possible?
If I use 2.95, it's okay. (or all other numbers I have tested until now)
In our apps where we have money amounts, float values are used only for display. Everything is stored and computed as integers (or longs).
e.g. 1.37 (display) = 137 (integer)
 
Upvote 0
Yes, but I understand it too late.. :confused::confused:
 
Upvote 0
Back
Top