Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper way to do rounding for currency conversion in Paypal?

I'm building an ecommerce site integrated with paypal.

We take multiple currencies, so I want to make sure that (for accounting reasons) i'm correctly performing any math for currency conversion.

After multiplying the currency conversion * the original currency, I always end up with lots of trailing numbers after the decimal point.

Is there a standard way to do this? Should I truncate or round? Do I need to round multiple times in case rounding the 1/1000 decimal will affect rounding the 1/100 decimal?

Should I be doing something like:

Math.Round(Math.Round(x, 3), 2)

I've been having trouble finding good information about how this is done (hopefully US and Europe are the same).

like image 363
Ralph N Avatar asked Jan 03 '12 19:01

Ralph N


People also ask

How do I change my currency on PayPal 2022?

Log into your PayPal account. Go to your Wallet page. Click the Options icon beside the currency you want to convert which is USD. Click Convert currency.

How do I stop PayPal from converting currency?

Via PayPal: Always click "See currency options" and pay in the seller's currency to avoid the PayPal currency conversion fee. Via the cheapest option: Use Revolut to make instant, low-cost payments in a foreign currency.


1 Answers

if your site has multiple currencies then use this to correctly round decimals according to the current user's currency and culture :

int currencyDecs = System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyDecimalDigits;
decimal roundedDecimalPrice = Math.Round(decimalPrice, currencyDecs, MidpointRounding.AwayFromZero);
like image 124
Chtiwi Malek Avatar answered Oct 11 '22 10:10

Chtiwi Malek