PHP Classes

Thousand separator in numbers

Recommend this page to a friend!

      PHPXBase  >  All threads  >  Thousand separator in numbers  >  (Un) Subscribe thread alerts  
Subject:Thousand separator in numbers
Summary:Suggesting a correction for the setInt method of Record class
Messages:3
Author:Peter Papp
Date:2006-11-27 18:20:38
Update:2013-03-19 14:06:22
 

  1. Thousand separator in numbers   Reply   Report abuse  
Picture of Peter Papp Peter Papp - 2006-11-27 18:20:38
Hi!

I noticed that by Sergiu Neamt's suggestion, you are using the number_format PHP function in the setInt mehtod of the Record class. The initial idea is good, however, this will leave a thousand separator (",")in the number, thus it will be written to the dbf table incorrectly. I suggest the following change:

Instead of:
$this->forceSetString($columnObj,number_format($value, $columnObj->decimalCount);

Try this:
$value = number_format($value, $columnObj->decimalCount);
$value = str_replace(",", "", $value);
this->forceSetString($columnObj, $value);

Best regards,
4P

  2. Re: Thousand separator in numbers   Reply   Report abuse  
Picture of Jirka Jirka - 2007-09-12 20:55:45 - In reply to message 1 from Peter Papp
Hi I had the same problem
solution which works for me:

The "float" column was defined as "numeric" (try to check col headers from test.php)
Numeric fields are read as INT

find function getInt($columnObj) //line 170 Record.class.php
change line:
return intval($s); //175
to
return floatval($s);
Jirka

  3. Re: Thousand separator in numbers   Reply   Report abuse  
Picture of prokee prokee - 2013-03-19 14:06:22 - In reply to message 1 from Peter Papp
I had some problems with writing numbers under 999 to the DBF file.
Tried your suggestion, replaced this line:
$this->forceSetString($columnObj,number_format($value, $columnObj->decimalCount));

...to this:

$value = number_format($value, $columnObj->decimalCount);
$value = str_replace(",", "", $value);
$this->forceSetString($columnObj, $value);

(that's your idea, just fixed some missing characters)

...in file Record.class.php, and works fine - thanks!