[Gambas-user] Custom library function returns wrong value

Jussi Lahtinen jussi.lahtinen at ...626...
Thu Feb 5 17:24:02 CET 2015


Here is the actual 64bit presentation for number 38.37:
38.36999999999999744204615126363933086395263671875


Jussi

On Thu, Feb 5, 2015 at 6:20 PM, Jussi Lahtinen <jussi.lahtinen at ...626...>
wrote:

> 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.999999
> 3837
>
> Print StrMoneyToInt("38.37") 'This prints the integer, which is created by
> cutting fractional part.
> 3836
>
> Print Cint(f)
> 3836
>
> Print Frac(f)
> 0.999999 something
>
>
> Floating points are confusing. I suggest to use Round() function.
>
> Print CInt(Round(f))
> 3837
>
>
>
> Jussi
>
>
>
> On Thu, Feb 5, 2015 at 5:28 PM, bill-lancaster <bill-lancaster at ...2231...
> > wrote:
>
>> 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-function-returns-wrong-value-tp50542p50544.html
>> Sent from the gambas-user mailing list archive at Nabble.com.
>>
>>
>> ------------------------------------------------------------------------------
>> Dive into the World of Parallel Programming. The Go Parallel Website,
>> sponsored by Intel and developed in partnership with Slashdot Media, is
>> your
>> hub for all things parallel software development, from weekly thought
>> leadership blogs to news, videos, case studies, tutorials and more. Take a
>> look and join the conversation now. http://goparallel.sourceforge.net/
>> _______________________________________________
>> Gambas-user mailing list
>> Gambas-user at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>
>



More information about the User mailing list