Hi,
this is simple with "case" or "iif"
this run ok
SELECT CASE WHEN CAST('123.00' AS INTEGER)<>CAST('123.00' AS NUMERIC(18, 3))
THEN CAST('PRECISION LOST' AS INTEGER) ELSE CAST('123.456' AS INTEGER) END FROM
RDB$DATABASE
this run with an error "conversion error from string "PRECISION LOST FOR
123.456""
SELECT CASE WHEN CAST('123.456' AS INTEGER)<>CAST('123.456' AS NUMERIC(18, 3))
THEN CAST('PRECISION LOST FOR 123.456' AS INTEGER) ELSE CAST('123.456' AS
INTEGER) END FROM RDB$DATABASE
regards,
Karol Bieniaszewski
W dniu 2015-05-25 12:04:09 użytkownik [email protected] [firebird-support]
<[email protected]> napisał:
Hello,
is it possible by using CAST or in any other way to get database error when
casting such number to integer?
SELECT CAST('13.245' AS INTEGER) FROM RDB$DATABASE
This gives 13 but instead I would like to get an error because precision is
lost.
However, I would like to NOT get an error when doing this:
SELECT CAST('13.000' AS INTEGER) FROM RDB$DATABASE
Becasue here precision is not lost.
Is it possible to obtain such behaviour in easy way or do I have to use regular
expressions?
Best regards.
Re: [firebird-support] How to CAST float to integer with error?
liviuslivius [email protected] [firebird-support] Tue, 26 May 2015 00:56:37 -0700
- ... [email protected] [firebird-support]
- ... Svein Erling Tysvær [email protected] [firebird-support]
- ... liviuslivius [email protected] [firebird-support]
- ... [email protected] [firebird-support]
