Subject Re: [firebird-support] Round() returning NULL
Author Helen Borrie
At 08:06 PM 5/10/2004 +0000, you wrote:

>Hi All,
>I'm using the Round() UDF from fbudf in a stored procedure and it's
>returning NULL. I'm doing a select...into and setting a Double
>Precision variable to 115.84. When I pass this variable to the UDF,
>it returns NULL to the integer variable I'm assigning.
>dSales = 115.84;
>iSales = Round(:dSales);
>What am I doing wrong?

1) remove the colon from the argument (the colon is invalid unless
referring to variables in SQL statements)

2) Look at the arguments in your declaration.

>The UDF is declared as:
>declare external function Round
> int by descriptor, <------ input 1: number to be rounded
> int by descriptor
> returns parameter 2
> entry_point 'fbround' module_name 'fbudf';

You are getting null because you are passing a double precision number to
it. You need to recast your input variable as numeric for it to be
compatible with the integer argument. How you do that depends on how you
are getting the input number. If the variable has to be a double, then
cast it in the function call:

select round(cast(115.84 as numeric(18,6)) as blah from rdb$database

which returns 116.

If the variable can be a numeric, then declare it as such and use a cast
expression to load its value.