PHP Classes

Incorrect rounding with number_format

Recommend this page to a friend!

      Top level forums  >  PHP Specialists  >  General  >  Incorrect rounding with number_format  
Subject:Incorrect rounding with number_format
Summary:Incorrect rounding with number_format
Messages:2
Author:Richard Fennah
Date:2010-10-19 11:47:25
Update:2010-10-26 03:14:31
 

  1. Incorrect rounding with number_format   Reply   Report abuse  
Picture of Richard Fennah Richard Fennah - 2010-10-21 19:39:13
I am currently running the following:

$vatcost = ($amount/100)*$vat;
$totalvat = $totalvat + $vatcost;
$totalvat = number_format($totalvat, 2, '.', '');

At the start of this code $vatcost is 47.915.

Using basic maths this should round to 47.92, however every time this code is run I am getting 47.93!

Does anything seem odd with my code or is this a bug within number_format?

Thanks.

There is 1 reply in this thread, which is not being displayed.
Browsing this forum thread replies is available only to premium subscribers.


Go to the premium subscriptions page to learn how to become a premium subscriber and have full access to this forum.