The correct way to calculate prices, including tax in foreign currency

I am trying to update the application so that I can sell several countries. I save all my prices in the database in GBP, excluding tax up to 4dp, and I need to calculate prices in the currency of the country, including taxes.

Do I multiply the price at the exchange rate versus the price excluding tax (option 1) or do I calculate the amount, including tax, and then a few at the exchange rate (option 2)? I also added option 3, watching how OpenCart computes it, which is similar to option 2, but only ever rounded when it is displayed. Here is the formula for all three options:

Option 1:

Round ((Price * Exchange rate) / 100 * (100 + tax rate))

Option 2:

Round (Round (Price / 100 * (100 + tax rate)) * Exchange rate)

Option 3:

Round ((/100 * (100 + )) * )

, 89.99. 1,5 20%. :

1:

((89,99 * 1,5)/100 * (100 + 20)) = 161,98

2:

Round (Round (89.99/100 * (100 + 20)) * 1.5) = 161.99

3:

((89,99/100 * (100 + 20)) * 1,5) = 161,98

, OpenCart . , :

((/100 * (100 + )) * * )

, 3 , :

((89,99/100 * (100 + 20)) * 3 * 1,5) = 485,95

, , OpenCart - ( ) 161,98 485,95. , 161,98 * 3, 485,94, .

, , , . , - , , , .

+6
3

, Exchange Rate, , , : 1.3462, :

// I'm guessing you need it in PHP
$price = 89.99;
$quantity = 1;
$tax = 20;
$tax = $tax/100.0 + 1;
// $tax = 1.2
$exchangeRate = 1.5;

$totalPrice = $price*$quantity*$tax;                     // Test #1
$totalPriceRounded = round($price*$quantity*$tax,2);     // Test #2

echo $totalPrice.'<br/>'.$totalPriceRounded;

:

107.988   // Test #1 <--- This is amount that needs to be paid to you and Great Britain
107.99    // Test #2 <--- rounded

, , , ? , , , GBP, . , , , , .

:

$totalPrice = round($totalPrice * $exchangeRate,2);
$totalPriceRounded = round($totalPriceRounded * $exchangeRate,2);

echo $totalPrice.'<br/>'.$totalPriceRounded;

:

// Amount in foreign currency
161.98      // Test #1
161.99      // Test #2

, , , 107.988 GBP, GBP .

// To calculate the totalPrice back to price*tax*quantity in GBP
$totalPrice /= $exchangeRate;
$totalPriceRounded /= $exchangeRate;

echo $totalPrice.'<br/>'.$totalPriceRounded;

:

// totalPrice in GBP currency
107.98666666667       // Test #1
107.99333333333       // Test #2

:

$totalPrice /= $tax;
$totalPriceRounded /= $tax;

echo $totalPrice.'<br/>'.$totalPriceRounded;

:

// the amount you get in GBP currency
89.988888888889    // End result of Test #1
89.994444444444    // End result of Test #2

, , in this case, round($price*$quantity*$tax*$exchangeRate, 2), , round(round($price*$quantity*$tax,2)*$exchangeRate, 2), , . , , , , .

  • , fixed prices, ( ), , ( ) . (.. round ) , . , , , / .

  • random prices, , , web servers, $0.01/second. / . , . , , . , , .

-, , :

$price = 4.47;
$quantity = 1.2    // lets say liters

// Even round the price before applying tax
$totalPrice = round($price * $quantity, 2);

, , .

, :

// Round once at end
$totalPrice = round($price*$quantity*$tax*$exchangeRate, 2);

, , , , . , , , , .

, // .. , , , .

+1

, . , , - , . , . , , .

+1

All Articles