2

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

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
prabhu
  • 919
  • 2
  • 12
  • 28

1 Answers1

1

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
  • 68,052
  • 28
  • 140
  • 210
  • 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 Apr 20 '10 at 13:02
  • Hmm.. That's true. Is there a way to use this casting with the C host variables? – prabhu Apr 20 '10 at 13:59
  • This is rather intended to let informix do the casts so that the datatypes directly fit the host-values. – stacker Apr 21 '10 at 11:27