Adam,
> I asked this question about4 months ago and I never got a response.
> So, I will ask again.
>
>
> Using DBD::XBase, when I create tables with floating point columns,
> the table has the numbers with the the decimals truncated. I have
> created the file using the following command
>
> $db_out->do('CREATE TABLE SHEPC.dbf (SHBUSU CHAR(8), SHFAC CHAR(3),
> SHDMG
> float, SHFCS float, SHSLA float, SHPDS float)') or die "Cannot create
> table: $DBI::errstr\n";
>
>
> I have tried variations of the float command with attempts to set the
> precision. All attempts leave me with a table that WILL NOT carry the
> decimals. Is there something simple I am doing wrong, or something I
> don't read in the DBD::XBase documentation?
>
> Adam
I reproduced your problem and found that it is a documentation issue.
DBD::XBAse is basically a wrapper around XBase.pm. Following the
XBase.pm pod, you can manually set the field width and the decimal
precision for float fields, and it says that it will assume
reasonable defaults if none are specified. Reading through the code
of XBase.pm I found that it sets the the field width to 8 (line 674)
and the decimal precision to *zero* (line 680) for float fields by
default (It may be doubted if zero decimal precision is reasonable
for float fields). Reading through the code of XBase::SQL, which
transforms the SQL statements for XBase.pm, lines 67-69 say that we
can specify the field width and precision of float fields in our SQL
statement as well. So,
my $sql = "CREATE TABLE $table ( float_field float(15, 8))";
will create a float field holding 15 digits, 8 of which are right of
the decimal separator. Notice that decimal precision and field width
must be manually be checked to fit with your number, as there seem to
be no warnings if things don't fit (e.g., a field width lesser than
the decimal precision etc). The above has worked for me.
HTH
Bodo