Dim S As String
Dim F As Float = 5.55
S=F
Log(S)
Log(F)
Private Sub CutDec(num As Float, DecCount As Int) As Float
Dim dec As Int
Dim intPart As Int = num
If DecCount < 1 Then Return(intPart)
Dim decPart As Float = num - intPart
dec = decPart * Power(10,DecCount)
Return(intPart + (dec / Power(10,DecCount)))
End Sub
Sub Globals
Type myType(F As Float, G As Float)
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim S As String
Dim F As Float = 5.55
S=F
Log(S)
Log(F)
' Until here it's not working
' Now look at this
Dim mt As myType
mt.F = F
Log(mt.F)
Log(mt.G)
Log(mt) 'so this is working?
S=S
End Sub
Sub Globals
Type myType(F As Float)
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim m As myType
m.F = 5.55
Log(m.F) ' here the result is: 5.550000190734863
Log(m) ' here the result is: [IsInitialized=false, F=5.55]
End Sub
5.55 cannot be represented exactly in base 2 (binary). So there will always be a very small inaccuracy. The result will be exactly like the result you get if you write similar code in Java, C, C# or any other language.So in the end if we have a variable v, declared as float, with value of 5.55 and we do v*v,
the result inside v, will be correct, right?.
No. The number is not wrong. It is just rounded.What will be wrong it will be the string representation of a number, unless using FormatNumber.
This is actually a bad idea. In 99.99% of the cases float or double accuracy is good enough. For the other 0.01% the developer can use the BigNumbers library instead.But I'm also saying, if you push it a little forward, to make it even more useful, I think, it's not a bad idea.
What do you think about it?
Note that this is exactly the same situation as in Java (and other languages).
5.55 cannot be represented exactly in base 2 (binary). So there will always be a very small inaccuracy. The result will be exactly like the result you get if you write similar code in Java, C, C# or any other language.
"Log" converts the parameter to a string before logging it.Please,
read carefully post #5, post #7 and post #9.
Log(m.F) return 5.550000190734863 (inaccuracy)
Log(m) return F=5.55 (where is the inaccuracy?)
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?