Re: [Firebird-devel] Strange CAST result

2022-05-25 Thread Mark Rotteveel

On 25-05-2022 10:08, artyom.abakumov wrote:

The CAST function returns a strange result in the following case:

SQL> SELECT CAST(345.12e-2 as VARCHAR(10)) from RDB$DATABASE;

CAST
==
3.45

Is it a correct behavior?
LI-V4.0.2.2770 Firebird 4.0


It does seem off, I would expect it to output 3.4512, same as happens 
for cast(3.4512e0 as varchar(10)).


There are other oddities, e.g. cast(x as varchar(10)) where x is a 
literal gives weird results:



34512e-4: 3.4512000
3451.2e-3   : 3.5
34.512e-1   : 3.451
3.4512e0: 3.4512
0.34512e1   : 3.45120
0.034512e2  : 3.451200
0.0034512e3 : 3.4512000

These should basically be the same value

Also
select cast(x as varchar(10)) from (select cast(345.12e-2 as double 
precision) as x from rdb$database);


results in 3.3412000

while
select cast(x as varchar(10)) from (select 345.12e-2 as x from 
rdb$database);


results in 3.45, which is odd as 345.12e-2 is a double precision 
literal, but it looks like it gets coerced to something else in the 
presence of the cast to varchar.


Mark
--
Mark Rotteveel


Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel


[Firebird-devel] Strange CAST result

2022-05-25 Thread artyom.abakumov

Hi!

The CAST function returns a strange result in the following case:

SQL> SELECT CAST(345.12e-2 as VARCHAR(10)) from RDB$DATABASE;

CAST
==
3.45

Is it a correct behavior?
LI-V4.0.2.2770 Firebird 4.0

Artyom



Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel