php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73447 Floats written to character fields are truncated to integer
Submitted: 2016-11-02 18:42 UTC Modified: 2016-11-02 19:08 UTC
From: cmb@php.net Assigned: cmb (profile)
Status: Closed Package: dbase (PECL)
PHP Version: 5.6.27 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: cmb@php.net
New email:
PHP Version: OS:

 

 [2016-11-02 18:42 UTC] cmb@php.net
Description:
------------
If a float value is written to a character field ('C') all decimals are
discarded, and only the integral part of the number is written. Also,
the number is right padded to the field length. This regression has been
introduced by fixing bug #39305.


Test script:
---------------
<?php

$filename = __DIR__ . DIRECTORY_SEPARATOR . 'dbase-trunc.dbf';

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

dbase_add_record($db, [123.45]);
var_dump(dbase_get_record_with_names($db, 1));


Expected result:
----------------
array(2) {
  ["FLOAT"]=>
  string(15) "123.45         "
  ["deleted"]=>
  int(0)
}


Actual result:
--------------
array(2) {
  ["FLOAT"]=>
  string(15) "            123"
  ["deleted"]=>
  int(0)
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-11-02 18:42 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2016-11-02 18:55 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=340846
Log: Fix #73447: Floats written to character fields are truncated to integer

We must not apply _php_math_number_format_ex() on fields where db_fdc
doesn't have a meaningful value. Instead we can rely on normal to string
conversion for these cases.
 [2016-11-02 19:08 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 01:01:28 2024 UTC