views:

222

answers:

1

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

+1  A: 

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
stacker
Thanks for the answer. Learnt something new. But I'm more inclined to do this outside the query because I usually select multiple columns all the time.It will be good to know about a function that can do this outside the query.
prabhu
Having this among other columns in a query works also.
stacker
Hmm.. That's true. Is there a way to use this casting with the C host variables?
prabhu
This is rather intended to let informix do the casts so that the datatypes directly fit the host-values.
stacker