PHP Classes

Numeric fields with float

Recommend this page to a friend!

      PHPXBase  >  All threads  >  Numeric fields with float  >  (Un) Subscribe thread alerts  
Subject:Numeric fields with float
Summary:Suggestion: make the numeric field read float not only int.
Messages:1
Author:Lauro Araujo
Date:2009-05-14 18:47:52
 

  1. Numeric fields with float   Reply   Report abuse  
Picture of Lauro Araujo Lauro Araujo - 2009-05-14 18:47:52
Hi,

Many of the dbf files I'm working with store float values as NUMERIC fields, and the Record class treats these as integers:

function getObject($columnObj){
...
case DBFFIELD_TYPE_NUMERIC : return $this->getInt($columnObj);
}

I suggest the creation of a new function getNumeric() that can read both int and float:

case DBFFIELD_TYPE_NUMERIC : return $this->getNumeric($columnObj)

function getNumeric($columnObj) {

if ($columnObj->getType()!=DBFFIELD_TYPE_NUMERIC) trigger_error ($columnObj->getName()." is not a Number column", E_USER_ERROR);
$s = $this->forceGetString($columnObj);
if (!$s) return false;
$s = str_replace(",",".",$s);

//Only differs from getInt() here - Checks if numeric, othewise, converts to integer.

if(is_numeric($s)) return $s;
return intval($s);

}