Re: Multiply - seemed to be so very easy

From: Date: Mon, 11 Nov 2002 10:16:11 +0000
Subject: Re: Multiply - seemed to be so very easy
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-123795@lists.php.net to get a copy of this message
On Monday 11 November 2002 17:20, Tomasz Ciesielski wrote: > Hi. That's my problem: > class MYCLASS { > var $z = array(); > function addOne($PRODUCT_ID,$IL,$PR) { > $this->z[$PRODUCT_ID]=array("IL" => $IL, > "PR" => $PR); > } > function myPrice() { > $cn = 0.0; > reset($this->z); > while (list($id,$vals) = each($this->z)) { > problem here! -> $cn=$cn + $vals["PR"]*$vals["IL"]; Be creative! - Use print() on $vals["PR"] and $vals["IL"] to see what they contain - assign them to temp variables, then assign their multiplied value to a third temp variable, then print() all three. - you get the idea. > } > reset($this->z); > return $cn; > } > } > > Example to above: > $this->z[1] = array ("IL" => 1, "PR" => 634.4); > then function myPrice() counts $cn as 634 (not as 634.4)!!! > It works like that even when I convert $vals["PR"] and $vals > ["IL"] to floats. -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* Bilbo's First Law: You cannot count friends that are all packed up in barrels. */

« previous php.general (#123795) next »