Convert float to decimal in Informix

prabhu picture prabhu · Apr 20, 2010 · Viewed 7.6k times · Source

I have a table with a column of type decimal. There is a ESQL/C structure that represents the table. It has a member of type decimal. I also have a normal C structure for equivalent for the same table. The type of the above mentioned field is a float.

Since we use memcpy to copy data to and from ESQL/C structure to C structure, there is an issue with decimal to float conversion. When I searched the Informix ESQL/C Programmer's manual, I couldn't find any function that can do this. Google search led me to the deccvflt() function. This function converts from a float to a decimal type.

Though I couldn't find this function listed in the manual, I see the declarations in decimal.h. Are these functions still recommended to be used?

Alternatively, I was also thinking about using the decimal type in the C structure also, as it happens to be a C structure. This way, I can still use the memcpy right?

Please share your thoughts.

IBM Informix Dynamic Server Version 11.50.FC3

Thanks, prabhu

Answer

stacker picture stacker · Apr 20, 2010

You could convert to float or decimal directly in your query using a cast

select name_of_float::decimal(8,2) from table

or

select name_of_decimal::float from table