Subject AW: [firebird-support] Re: convert, cast
Author Olaf Kluge
--- In firebird-support@yahoogroups.com
<mailto:firebird-support%40yahoogroups.com> , "Olaf Kluge" <olaf.kluge@...>
wrote:
>
> Hello
>
>
>
> I have a litte stored procecure which converts a string into a number:
>
>
>
> CREATE PROCEDURE U_CN_TO_INT (
>
> CN_IN VARCHAR (15))
>
> RETURNS (
>
> INT_OUT INTEGER)
>
> AS
>
> BEGIN
>
> int_out = cast(cn_in as integer);
>
> SUSPEND;
>
> END
>
>
>
> Cf_in is the input string containing the following: 0000001234
>
> I get with the output-variable int_out the number 1234. A other procedure
> converts a string into a floating point 000012345999 into 12345.999 with
the
> same problem:
>
>
>
> If the input value is not a string with leading zeros, I get an error.
>
>
>
> How can I check that bevore I cast the value?
>
>
>
> Thank you.
>
>
>
> Best regards
>
>
>
> Olaf
>
>
>
> [Non-text portions of this message have been removed]
>

what error?
and how look this procedure for floating point numbers?



Hi,



If the input not a valid integer as varchar with leading zeros, then I get
the error "overflow occurred during data type conversion. Conversion error
from string "00000015A" at procedure u_cn_to_int line 7 col 3" Without the
'A' it does work.

How can I check that before?



The procedure for floating point numbers:



CREATE PROCEDURE U_CF_TO_DP (

CF_IN VARCHAR (15),

NKST INTEGER)

RETURNS (

DP_OUT DOUBLE PRECISION)

AS/

declare variable tmp_int integer;

BEGIN

tmp_int = cast(cf_in as integer);

dp_out = tmp_int/f_pow(10,nkst);

SUSPEND;

END



I get normally a string '00000163123' The last 3 chars are decimal places,
so the double precision value is 163.123. This procedure works fine, but if
the input-string includes letters, I get an error like described above.



Thanks for helping.



Olaf



[Non-text portions of this message have been removed]