I'm doing some calculations on both client and server, and I've found a difference in the final result.
What am I doing wrong and what would be the correct way for obtaining a 2 decimal float for representing currency.
Consider the following code (final number without format is 1,785):
JS
var sum = parseFloat(8.50);
var tax = parseFloat(21.00);
var total = parseFloat(sum * (tax / 100));
var test = total.toFixed(2);
console.log(test);
PHP
$sum = (float)"8.50";
$tax = (float)"21.00";
$total = (float)($sum * ($tax / 100));
$test = number_format($total, 2, ".", "");
echo $test;
In JS I get 1.78
and in PHP 1.79