Jump to content

Simple math baffling me!


elentz

Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
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.