IBM Support

CAST to DOUBLE is an approximation

Question & Answer


Question

The following SQL statement returns different results in DSNTEP2 and SPUFI: SELECT CAST(265.84 AS DOUBLE) FROM SYSIBM.SYSDUMMY1 WITH UR;

Cause

In DSNTEP2 the query returned: 2.658399999999999E+02

In other interfaces, like SPUFI, a more precise result was returned: +0.2658400000000000E+03

Floating-point numbers are an approximation. DB2 for z/OS passes back the same floating-point number to both applications--DSNTEP2 and SPUFI. However, these applications then translate the floating-point number into a string for display. Apparently, DSNTEP2 and SPUFI have different ways of translating the floating point numbers into strings, and some variation even occurs at different maintenance levels, but the values are very close.

Answer

Putting CHAR around the result causes the conversion from floating point to string to be done by the DB2 for z/OS server instead of by the different applications. For example, you could modify the query as follows: 

SELECT
CHAR(CAST(265.84 AS DOUBLE))
FROM SYSIBM.SYSDUMMY1;

                                             
The modified query returns the following value in DSNTEP2: 2.6584E2

[{"Product":{"code":"SSEPEK","label":"Db2 for z\/OS"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"RDS","Platform":[{"code":"PF035","label":"z\/OS"}],"Version":"10.0;11.0;12.0","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Document Information

Modified date:
20 June 2019

UID

swg21254474