Have written a simple PHP program to get data from a database to an accounting program. Therefore I need to do some calculations. And one of them goes completely wrong.

<?php
$prijs = 480.00;
$nvh = 432.00;
$prov = 40.34;
$btw = 7.66;

$over = $prijs - ($nvh + $prov + $btw);
$tmp = ($nvh + $prov + $btw);

echo $prijs."\n";
echo $tmp."\n";

echo $prijs - $tmp."\n";
echo $over."\n";

?>

The result should be $over == 0 and $prijs - $tmp should also be 0.
But I get the following output:
480
480
-5.6843418860808E-14
-5.6843418860808E-14

Anybody? What is going on here?

Recommended Answers

All 2 Replies

Read the warning:
http://php.net/manual/en/language.types.float.php

Thanks for pointing me in the right direction. bcsub does do the trick.
Never thought you would need it when you only add or subtract some numbers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.