I know dealing with float columns are fraught with rounding errors, but I'm
just wondering about the best way to deal with them.

I'm using DBD::Sybase, and some of our floats have the smallest
possible value... -1.7976931348623157e+308

When I just do:

select float_column from my_table

into a perl variable, and use it to insert into another table,
I get an error because the value gets rounded to:
-1.79769313486232e+308
which is too small to fit in a float column.

So, either I can:
select convert(varchar, float_column) from my_table

or instead, after selecting, I can use sprintf:
$float_column = sprintf("%1.16e", $float_column);

The first solution is okay if I know in advance which columns are floats,
while the second solution seems better if I need to dynamically deal
with unknown column types (e.g., "select *").

Does anyone have any better (or just other) ideas?

A DBI or DBD "select float as string" sort of flag would be nice that
would automatically do the conversion...is that
a good idea, or would it be feasible?

Thanks,
Doug

Reply via email to