On Tue, 2008-10-07 at 09:02 -0700, Douglas Wilson wrote:
> 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?
sprintf is the preferred way of rounding off floats in Perl. There is a
whole branch of mathematics, numerical analysis, which deals with
problems like this, so don't expect things to be easy.
BTW, don't use "SELECT *". If your DBA rebuilds the tables with a
different column order, your code will fail. Specifically name the
columns (or if you really have to, use the _hashref methods to fetch;
that way you can select the correct column via the hash).
--
Just my 0.00000002 million dollars worth,
Shawn
Linux is obsolete.
-- Andrew Tanenbaum