I have a problem with maths!
I am inputting a numeric into a text control on a form (eg "12.34".
I can take the integer portion via:
dim xnInt as Integer
xnInt=CInt(text1.text)
To get the decimal portion I do this:
dim xnWrk as Double
dim xnDec as Double
xnWrk=CDbl(text1.text)
xnDec=xnWrk-xnInt
When I use 12.34 as the value, I correctly get 12 for Int and 34 for Decimal.
When I use 12.345, I get 12 for Int, but 345000000000001 as the decimal.
As a further test, if I add the decimal portion to the integer portion, it always comes back to the starting figure - even though I don't see how!
eg
Int 12 + dec .34 = 12.34
Int 12 + dec .345000000000001 = 12.345
Anybody have any ideas as to why?
I am inputting a numeric into a text control on a form (eg "12.34".
I can take the integer portion via:
dim xnInt as Integer
xnInt=CInt(text1.text)
To get the decimal portion I do this:
dim xnWrk as Double
dim xnDec as Double
xnWrk=CDbl(text1.text)
xnDec=xnWrk-xnInt
When I use 12.34 as the value, I correctly get 12 for Int and 34 for Decimal.
When I use 12.345, I get 12 for Int, but 345000000000001 as the decimal.
As a further test, if I add the decimal portion to the integer portion, it always comes back to the starting figure - even though I don't see how!
eg
Int 12 + dec .34 = 12.34
Int 12 + dec .345000000000001 = 12.345
Anybody have any ideas as to why?