Here is the actual 64bit presentation for number 38.37:
38.36744204615126363933086395263671875
Jussi
On Thu, Feb 5, 2015 at 6:20 PM, Jussi Lahtinen
wrote:
> It is not the same function, the other "returns" float and the other
> returns integer.
>
> f = 38.37 * 100
>
> Print f 'This
It is not the same function, the other "returns" float and the other
returns integer.
f = 38.37 * 100
Print f 'This prints the float, which is rounded from ~3836.99
3837
Print StrMoneyToInt("38.37") 'This prints the integer, which is created by
cutting fractional part.
3836
Print Cint(f)
38
Thanks Fabien,
Yes, I have done that and the problem is fixed.
It was interesting that the same function in different locations can produce
different answers. I suppose that is the risk with float values.
Bill
--
View this message in context:
http://gambas.8142.n7.nabble.com/Custom-library-fun
And if you do only :
Cint(Replace(sValue,".",""))
This would avoid float round errors
2015-02-05 12:13 GMT+01:00 bill-lancaster :
> I have a Procedure in MyLib to convert a 'money' string to integer value.
>
> Static Public Procedure StrMoneyToInt(sVal As String) As Integer
> Dim f As Float
>
I have a Procedure in MyLib to convert a 'money' string to integer value.
Static Public Procedure StrMoneyToInt(sVal As String) As Integer
Dim f As Float
f = Val(sVal)
Return f * 100
End
Some values are incorrectly returned. For example:-
This code calls the procedure
Dim sMoney As S
Thank you both - I'm learning!
--
View this message in context:
http://gambas.8142.n7.nabble.com/Problem-with-OPTIONAL-method-declaration-tp50515p50541.html
Sent from the gambas-user mailing list archive at Nabble.com.
---