|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-11-02 12:57 UTC] cmb@php.net
-Assigned To:
+Assigned To: cmb
[2016-11-02 14:56 UTC] cmb@php.net
[2016-11-02 14:57 UTC] cmb@php.net
-Status: Assigned
+Status: Closed
[2016-11-03 14:28 UTC] cmb@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 07:00:01 2025 UTC |
Description: ------------ 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] <http://www.promotic.eu/en/pmdoc/Subsystems/Db/dBase/DataTypes.htm> [2] <http://www.okstate.edu/sas/v7/sashtml/books/acespc/z0214453.htm> [3] <http://www.oocities.org/geoff_wass/dBASE/GaryWhite/dBASE/FAQ/qfloat.htm> Test script: --------------- <?php $filename = __DIR__ . DIRECTORY_SEPARATOR . 'test.dbf'; $db = dbase_create($filename, [['FLOAT', 'F', 15, 5]]); dbase_close($db); $stream = fopen($filename, 'r'); fseek($stream, 48); $bytes = fread($stream, 2); var_dump(unpack('Clength/Cprecision', $bytes)); Expected result: ---------------- array(2) { ["length"]=> int(15) ["precision"]=> int(5) } Actual result: -------------- array(2) { ["length"]=> int(20) ["precision"]=> int(0) }