dlebowski Posted January 29, 2008 Share Posted January 29, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.