note 7982 added to Type Juggling
| From: | rhampton at veritime dot com | Date: | Wed, 23 Aug 2000 14:36:37 +0000 |
| Subject: | note 7982 added to Type Juggling | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-3017@lists.php.net to get a copy of this message | ||
We are using the money type of variable in a postgres database. When retrieving mfg_list_price, we
needed to recast this string as a numeric variable before doing multiplication. I came up with the
following solution:
<pre>
$mfg_list_price=ereg_replace("[^0-9.]","",$mfg_list_price);
#strip the leading $ sign
$mfg_list_price++;
$mfg_list_price--;
Our programmer, Joy Chen, noticed that this did not work properly -- every mfg_list_price was 0.01
higher than it ought to be. The solution was to substitute $mfg_list_price=$mfg_list_price+1; for
$mfg_list_price++; when recasting the variable.
This led to the proper solution.
http://www.php.net/manual/language.types.type-juggling.php