Hello,
PHP gives me wrong calculation results. !?
Example, PHP says that:
(47,60*554,82)/100 = 263,7
The right result is: 264
My code:
function kurs_usd($value) { // in use (usd to dkk)
$kurs = mysql_fetch_array(mysql_query("SELECT kurs, time FROM pvs.kurs WHERE id = 'usd'"));
if(time() >= $kurs['time']) {
$data = explode("\n", file_get_contents("http://www.nationalbanken.dk/_vti_bin/DN/DataService.svc/CurrencyRatesXML?lang=da"));
for($i = 0; $i < count($data); $i++) {
if(preg_match("/USD/i", $data[$i]) == 1) {
$kursp = strip(str_replace(" ", "", str_replace("\" />", "", str_replace("<currency code=\"USD\" desc=\"Amerikanske dollar\" rate=\"", "", $data[$i]))));
}
}
$time = time() + 3600;
mysql_query("UPDATE pvs.kurs SET `kurs` = '$kursp' WHERE id = 'usd'");
mysql_query("UPDATE pvs.kurs SET `time` = '$time' WHERE id = 'usd'");
}
////// This is where i tested the inputs, and there where no problems
echo "aaa " . $kurs['kurs'] . " aaa";
echo "aaa " . $value . " aaa";
////////////////////////////////////////////////////////////////////////
return round(($value * $kurs['kurs']) / 100, 2);
}
What is wrong?!?!?!?!??!? :-)