|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73442 Float fields always have precision 0
Submitted: 2016-11-02 12:57 UTC Modified: 2016-11-02 14:57 UTC
From: Assigned: cmb (profile)
Status: Closed Package: dbase (PECL)
PHP Version: 5.6Git-2016-11-02 (Git) OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2016-11-02 12:57 UTC]
When a DBF is created with dbase_create() all float fields ('F') have
their precision set to 0, so are in fact (inexact) integers[1][2].
Contrary to numeric fields ('N') there is no way to specify the field
length and precision.

Contrary to what one might assume, float fields are not supposed to
store real floating point numbers, but rather they are identical to
numeric fields with regard to the storage format. The only difference is
that as of dBASE IV (where float fields have been introduced) floats are
internally converted to IEEE floats (probably doubles) and numerics are
internally handled as BCD to offer exact calculations[3].

[1] <>
[2] <>
[3] <>

Test script:

$filename = __DIR__ . DIRECTORY_SEPARATOR . 'test.dbf';

$db = dbase_create($filename, [['FLOAT', 'F', 15, 5]]);

$stream = fopen($filename, 'r');
fseek($stream, 48);
$bytes = fread($stream, 2);
var_dump(unpack('Clength/Cprecision', $bytes));

Expected result:
array(2) {

Actual result:
array(2) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-11-02 12:57 UTC]
-Assigned To: +Assigned To: cmb
 [2016-11-02 14:56 UTC]
Automatic comment from SVN on behalf of cmb
Log: Fix #73442: Float fields always have precision 0

For compatibility with other dBASE tools, float fields have to be
treated like numeric fields, i.e. length and precision have to be
specified when a new DBF is created.
 [2016-11-02 14:57 UTC]
-Status: Assigned +Status: Closed
 [2016-11-03 14:28 UTC]
Automatic comment from SVN on behalf of cmb
Log: Fix #73442: Float fields always have precision 0

Ammendment for r340843: dbase_get_header_info() also has to report the
float field precision.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Jun 07 22:03:40 2023 UTC