osCommerce 4 osCommerce 4 App Shop Support Services App Shop Us
• Checkout
• Get in touch

osCommerce

The e-commerce.

# Currency Exchange and Product Pricing / Order Total Problem

## Recommended Posts

Ok well I discovered a problem related to currency exchange leading to your order totals.

Basically, lets say you have these variables

a default currency of USD (1.0 value)

now take a product with a value of 47.99 USD and a quantity of 7 (say).

With Canadian taxes of 13% this is what the invoice appears like

price (base) = 47.99 USD

price (final excl) = 47.99 USD

price (final incl) = 54.23 USD

price (total excl) = 335.93 USD

price (total incl) = 379.60 USD

Now this is just fine and dandy and as it should be.. now heres the problem.. if your default currency is USD.. then if the user selects CAD currency its going to use the function \$currencies->format(.....) right.. (well it uses it anyways with USD but with a value of 1.0 it makes no difference)

with CAD currency heres the problem..

price (base) = 48.01 CAD (47.99 * 1.000360)

price (final excl) = 48.01 CAD (47.99 * 1.000360)

price (final incl) = 54.25 CAD ((47.99 + 13%) * 1.000360) now this is wrong however the value still doesnt change.. it will soon though

price (total excl) = 336.05 CAD ((47.99 * 7) * 1.000360) = WRONG!!! THIS SHOULD BE 336.07! there are 2 CENTS MISSING .. the equation should be 48.01 * 7 not what it actually is.

finally price (total incl) = 379.74 (((47.99 * 7) + 13%) * 1.000360) = WRONG AGAIN!!! THIS SHOULD BE 379.76! AGAIN 2 CENTS MISSING.. the equation should be 48.01 * 7 + 13% ..

the exchange rate is messing everything up and i had to change the way everything was calculated in the admin section and catalog section.

just laying it out unless it was already discovered by others.. but I didnt know and realized it a couple days ago.. and I deal in some big orders and these values should be accurate...its only 2 cents but thats my 2 cents =P..

J

##### Share on other sites

Maybe try using 5 decimal places in your tax calculations.

##### Share on other sites

Maybe try using 5 decimal places in your tax calculations.

4 vs 5 is not the problem.. the problem is the actual equations that are in use.. when you use the currency rate to convert the value for a single product at for example 47.99 USD to CDN at a rate of 1.000360 then you get a value of 48.0072... this turns out to be 48.01 when you view the invoice.. but the total including tax is missing 2 cents.. ive fixed my site .. im just letting everyone else know to take a look at any orders which did not occur in their default currency and run the calculations by hand.. they may be missing a couple cents here and there..

Now what can be done is say just let the currency rate be at most 2 decimal places .. thus in this case just 1.00 then there is no problem.. but again.. there are then 2 cents missing.. the price of the product in canadian funds should be 48.01 not 47.99 (2 cents missing) ...

take another rate value of for example 1.323989 ... convert 47.99 USD to CAD .. = 63.54 CDN .. if I use 1.32 as the rate instead of 1.323989 I get a value of 63.35 .. see the difference now.. 19 cents!!

but again.. im just letting everyone else know that their stores may be calculating incorrectly .. ive fixed mine to calculate the correct order total amounts and to display the correct amounts on the invoices ...

J