[Gambas-user] A question about how "Frac" works

Benoît Minisini gambas at ...1...
Fri Dec 23 16:37:59 CET 2011


Le 23/12/2011 16:34, Santiago Oberto a écrit :
> Good Morning!
>
> Recently I have been devoloping an application in wich I needed to use
> several strings and numbers like if they were strings.
>
> I have been having a problem with this issue:
>
> I realized that when trying to use frac(my_float_number) I don't get the
> desired result. For instance:
>
> Print CString(Frac(5.025)) returns 0.0250000000000004 when I expected to
> get 0.025...
>
> Is this a common behaviour of this function and this is not suited for
> the pourpose I persuit?
>
> I am using Gambas 2.99.3 in a Fedora 14 32-bits Enviroment.
>
> Thanks in advanced!
>

This is normal, because 0.025 has no exact binary representation (like 
1/3 in decimal). So the fractional part of 5.025 must be approximated by 
the CPU.

Regards,

-- 
Benoît Minisini




More information about the User mailing list