Jump to content

Recommended Posts

I need assistance with these two pieces of code below.  My calculations are off when a dollar amount is entered. 

 

 

First Part:

$value1=1;

$BuyerCashPrem = ($value1/100);
$CashPaid = (($cash) * $BuyerCashPrem);

$sum=99;
$absenteebid=1;
$taxtotal=1;
$cash=0;
$CashPaid=0;
$BuyerCashPrem=.01;

$grandtotal = (($sum + $absenteebid + $taxtotal)-((($cash - $CashPaid))));
$cashprem=($grandtotal * $BuyerCashPrem);

<? echo "$cashprem";?>

VALUE DISPLAYED=1.01

 

This is correct!

 

Second Part:

$grandtotal = ($sum + $absenteebid + $taxtotal + $cashprem);
$AllPaymentTotal = (($cash)-($CashPaid));
$amountdue = ($grandtotal - $AllPaymentTotal);

print $amountdue;

VALUE DISPLAYED=102.01

 

Now, if my customer pays 102.01, that should take care of the balance.  It doesn't.  It actually makes "$cashprem=0.00010099999999994" and "$amountdue=0.010200999999995"  I have spent hours upon house using "round" and "number_format" and I cannot get it to be correct.  It is always off by at least .01.  Can anyone help on this.  If I didn't provide enough information, please let me know and I will get you more.  Thanks in advance.

 

Ryan

Link to comment
https://forums.phpfreaks.com/topic/88301-solved-rounding-monetary-value-issue/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.