Subject | RE: [firebird-support] Udf and Double Field |
---|---|
Author | Alan McDonald |
Post date | 2004-11-04T21:11:03Z |
> Hi,two things you can try.
> I am using firebird 1.5.1
> I have written an udf funtion with delphi 7.
> This function is called RoundDouble
> Here is the function code.
>
> Type
> DD = ^Double;
>
> Function RoundDouble (X : DD; NDigit : PSmallInt) : Extended; Stdcall;
> Var A,Sayi,Tamsayi,Kusurat : Extended;
> Begin
> Sayi:=X^;
> Tamsayi:=Int(Sayi);
> Kusurat:=Sayi - Tamsayi;
>
> if (Kusurat <> 0) Then
> Begin
> A:=Exp(NDigit^ * Ln(10));
> Kusurat:=Round(Kusurat * A) / A;
> End;
>
> Result:=Tamsayi + Kusurat;
> End;
>
> But this function is returns very sensitive numbers
>
> Example
> =======
> SELECT RoundDouble(1255521000.321313213,2),
> RoundDouble(1199392449.91999984,2) FROM RDB$DATABASE
> The result is that:
> 1255521000.31999993
> 1199392449.92000008
>
> but the result numbers are very sensitive
> the result must be
> 1255521000.32
> 1199392449.92
>
> what is the problem
> is this problem about firebird server
> i have tried another alternative but i can't find the solutions.
>
1. use the standard udf libary which will do the right thing - no need to do
it yourself, someone else has already invented this wheel.
OR
2. return your result as a varchar (2 places) and then cast the result as a
double on the client.
Alan