SQLCMD float bad conversion
Posted in 2005
Topics: Stored Procedures & SPL, Connectivity: ESQL/C, 4GL & Embedded SQL, Migration, Import/Export & Data Conversion, Third-Party Tools & Monitoring
Hi, I have a problem with the command "sqlcmd" (last version 77_08) and FLOAT type when i wish to unload to ASCII by this: sqlcmd -d database -e 'select col1 from tabname' the col1 (type float) doesn't display the good value example: if i have a row with a float type (ex:14492.38) it converts automatically to 14492.40. PS: ESQL/C 2.9 Informix SE 7.24 SQLCMD_77.08 Anyone can help me !! Thank You "L'action pese plus lourd que les mots"
hapion@yahoo.fr wrote: > I have a problem with the command "sqlcmd" (last version 77_08) and > FLOAT type when i wish to unload to ASCII by this: > > sqlcmd -d database -e 'select col1 from tabname' > the col1 (type float) doesn't display the good value > > example: > if i have a row with a float type (ex:14492.38) it converts > automatically > to 14492.40. > > > > PS: > ESQL/C 2.9 > Informix SE 7.24 > SQLCMD_77.08 > > > Anyone can help me !! The code in question is in a file called, with stunning originality, output.c. The particular bit you'll have to alter is the line that defines fmt_f and fmt_v, somewhere around line 78. The normal format is fmt_v (variable format), and the entry for float is %g. On your system, it appears that printf() plus %g doesn't do a particularly good job of handling float/double numbers. Edit those formats to suit yourself; recompile. If you're worried, you can specify lengths - as in the fmt_f line. Be aware that the double format (%21.13e) is quite conservative; you probably could change the 13 to 15 without too much difficulty, but going beyond that is probably tring to squeeze more information out the type than is available from it. With small float (C float), 7 digits is about the limit - but SQL FLOAT corresponds to C double and that should have precision to spare. It would be feasible to use some length-qualified variant of the %g format. -- Jonathan Leffler #include <disclaimer.h> Email: jleffler@earthlink.net, jleffler@us.ibm.com Guardian of DBD::Informix v2005.02 -- http://dbi.perl.org/
It's great !!! Thank you very much for your help (;-) Jonathan Leffler a écrit : > hapion@yahoo.fr wrote: > > I have a problem with the command "sqlcmd" (last version 77_08) and > > FLOAT type when i wish to unload to ASCII by this: > > > > sqlcmd -d database -e 'select col1 from tabname' > > the col1 (type float) doesn't display the good value > > > > example: > > if i have a row with a float type (ex:14492.38) it converts > > automatically > > to 14492.40. > > > > > > > > PS: > > ESQL/C 2.9 > > Informix SE 7.24 > > SQLCMD_77.08 > > > > > > Anyone can help me !! > > The code in question is in a file called, with stunning originality, > output.c. The particular bit you'll have to alter is the line that > defines fmt_f and fmt_v, somewhere around line 78. The normal format is > fmt_v (variable format), and the entry for float is %g. On your system, > it appears that printf() plus %g doesn't do a particularly good job of > handling float/double numbers. Edit those formats to suit yourself; > recompile. If you're worried, you can specify lengths - as in the fmt_f > line. Be aware that the double format (%21.13e) is quite conservative; > you probably could change the 13 to 15 without too much difficulty, but > going beyond that is probably tring to squeeze more information out the > type than is available from it. With small float (C float), 7 digits is > about the limit - but SQL FLOAT corresponds to C double and that should > have precision to spare. It would be feasible to use some > length-qualified variant of the %g format. > > -- > Jonathan Leffler #include <disclaimer.h> > Email: jleffler@earthlink.net, jleffler@us.ibm.com > Guardian of DBD::Informix v2005.02 -- http://dbi.perl.org/