Jump to content

Whats Wrong With This Code


FUNKAM35

Recommended Posts

I cannot see what is wrong with this code and have spent hours trying to get it to work:

 

if($pound==0  && $price >0 && $price <90000000){
$pound=$price*$euro;
$pound=number_format($pound);
$usd=$price*$usd;
$usd=number_format($usd,2);
$price=number_format($price);
   echo "<p>£ $pound approx</p><p>US   $ $usd Approx </p>\n";

}

 

The strange thing is that it works on the first item but not on subsequent items, it works every time for price and pound, it is the usd that is the problem, eg

 

first item everything correct:

€ 53,000

 

£ 45,298 approx

 

US $ 68,406.04 Approx

 

 

second item price and pounds correct but usd crazy:

€ 63,000

 

£ 53,845 approx

 

US $ 4,284,000.00 Approx

 

third item price and pounds correct but usd crazy

€ 68,250

 

£ 58,332 approx

 

US $ 273,000.00 Approx

 

Many thanks

Link to comment
https://forums.phpfreaks.com/topic/269039-whats-wrong-with-this-code/
Share on other sites

thanks, how do i reset the usd and why does it work for punds but not usd?

 

Pounds doesn't use $usd in the calculation, infact it doesn't use $pound in the calculation for pounds..

 

I'll explain:)

 

$pound=$price*$euro;

$pound=number_format($pound);

$euro never gets changed, $price changes in the increment the you want it to (from the loop) so everything is controlled properly in this

 

 

$usd=$price*$usd;

$usd=number_format($usd,2);

 

 

$usd IS getting assigned to the value of ($price * $usd), $usd originally (before the first loop), $price is controlled it increments the way you want it to.

AFTER the first loop $usd will equal something absurd and will screw up your calculations..

 

try this code instead:

 

 

if($pound==0 && $price >0 && $price <90000000){

$pound=$price*$euro;

$pound=number_format($pound);

$usd2=$price*$usd;

$usd2=number_format($usd2,2);

$price=number_format($price);

echo "<p>£ $pound approx</p><p>US   $ $usd2 Approx </p>\n";

 

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.