CalcBuilder Forum

Calculations Not Accurate on Large Numbers

User moon_474 2012-06-05 21:29:19

Hello,

I'm having an issue with this formula:

$cubic=$len1*$wit1*$hei1/166;
$sum=$cubic;
$actual=$act1;
if ($actual > $cubic)
$sum=$actual;
$sum=number_format($sum,2);
$cubic=number_format($cubic,2);
$total=$rates1*$sum;
$total=number_format($total,2);

On the site I have a cost calculator that takes the Length X Width X Height - The Actual Weight - and then multiples it by the chosen Rate.

I seems to work accurately with small numbers but when I enter 100x100x100 then 250 (for actual weight) and choose 1.57 per pound on the cost the results are not accurate.

The way this calculation is supposed to work (it does with smaller numbers) is it first calculates the cubic weight LxWxH which in this case would be 1,000,000 then compares it to the Actual Weight which is 250, then chooses the larger between the Cubic weight and Actual Weight and then multiples by the Rate..which is $1.57.

When I click calculate it spits out $9.49 when it should be $9457.84 - now if I take the LxWxH and use say 20x20x20 and 250 for the actual weight and $157 for the rate it calculates correctly at $392.50

I'm not sure why it is doing this...I figured a second set of eyes might see something I'm not.

Moonsoft support 2012-06-06 09:45:22

Hello,

It seems that you apply number format before a calc. Number format returns string not a float (number).

You can delete the following line:

$sum=number_format($sum,2);

All number format should be at the end.

Hope this helps. Regards,

User moon_474 2012-06-06 16:38:12

I knew it was something I overlooked...you guys are awesome!

Everything is working great now :)

...
Support/development 10 hours

Get a bigger amount of hours for more complex tasks and get a 10% discount

Buy now!
...
Support/development

Perfect for small code changes or to correct any bug at your site

Buy now!