elentz Posted November 24, 2007 Share Posted November 24, 2007 I am trying to do some simple math with some variables. I have tried everything I can think of and either I get the wrong number or it doesn't work at all. I want to replace the $price_total with $formatnet_total+$format_mitax-$price_adjustment+$price_shipping. Here's my code: [/code] // totals Block $totalBlock=array("120","235","40", "110"); $totalText="SubTotal: ".$formatnet_total."\n". "Sales Tax: ".$format_mitax."\n". "Adjustment/Payment: ".$price_adjustment."\n". "Late Fees: ".$price_shipping."\n". "Pay this amount:---->>>> $ ".$price_total; The output is going to a fpdf generated PDF. Thanks for looking! Quote Link to comment Share on other sites More sharing options...
Barand Posted November 24, 2007 Share Posted November 24, 2007 try calculating total using the unformatted values before you format them for output. $price_total = $net_total+$mitax-$price_adjustment+$price_shipping; Quote Link to comment Share on other sites More sharing options...
elentz Posted November 24, 2007 Author Share Posted November 24, 2007 Thanks for the reply Barry. I tried that and all I got was the product of the sales tax and the late fee. Now,given in this example that the net-total is 2109.25, the tax is 126.56, the late fee is 30.00, I should have a grand total of 2265.81. The grand total is already calculated elsewhere in the system. I would like to use my own. I think that the original script writers did not take into account rounding when it came to calculating taxes. This all stems from the fact that the grand total that is provided by the original writers is 2265.80. I thought I could get around this little 1 cent problem by using some simple math such as you provided, but for some reason it won't work. What is puzzling to me is that BOTH the net total and the sales tax are derived from Select Sum queries. And one of them is ignored (like it wasn't there) from the code you provided. Would it be possible to "remove" the rounding up for my tax calculation? Thanks Quote Link to comment Share on other sites More sharing options...
btherl Posted November 29, 2007 Share Posted November 29, 2007 Do you mean you got the sum, not the product? Have you checked that those values you added are set to what they should be? It seems very suspicious that a simple calculation like that would give wildly wrong results. Quote Link to comment Share on other sites More sharing options...
elentz Posted November 29, 2007 Author Share Posted November 29, 2007 to be truthful I don't know what I was getting. When I used Barry's code I got a result (whether it was a product or a sum) was 156.00. Makes no sense I could not figure out what it is doing. All the variables used are already calculated so it should be a straight forward thing. real goofy Quote Link to comment Share on other sites More sharing options...
btherl Posted November 29, 2007 Share Posted November 29, 2007 All the variables used are already calculated so it should be a straight forward thing. You can never assume things like this, especially when dealing with someone else's code Are you able to print out the value immediately before you do the calculation? And check that the spelling is identical? The only way such a simple calculation could fail is if the input isn't what you expected it to be. Quote Link to comment Share on other sites More sharing options...
elentz Posted November 29, 2007 Author Share Posted November 29, 2007 I can print all the variables, I haven't done it but I can see if they will print and report back. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.