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)
 

Star-Dust

Expert
Licensed User
Longtime User
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

Star-Dust

Expert
Licensed User
Longtime User
B4X:
Dim nVal As Long
Dim nPrice As Double
Dim S as string

nPrice = 8.95
S=nPrice
nVal = S.Replace(".","")
 
Upvote 0

Informatix

Expert
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)
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

Star-Dust

Expert
Licensed User
Longtime User
Yes, but I understand it too late..
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…