Hi
I'm having trouble with using round to round a vat calculation. I have done separated out the lines that I believe show the problem.
I can't work out why the first sprintf produces an incorrect rounded value, yet the second sprintf produces the required results. Driving me mad - can anyone put my mind at rest and stop my hair from turning grey? I'm sure it's something simple.
The code is:
<?php
$number = 691.30;
$withvat = $number * 1.15;
$total = $number * 1.15;
$vat = $total - $number;
?>
<?=sprintf("%.2F", round($vat, 2));?><br>
<?=sprintf("%.2F", round(103.695, 2));?>






Bookmarks