logoalt Hacker News

PaulDavisThe1st • yesterday at 4:06 PM • 1 reply • view on HN

This gets tricky when it comes to dealing with currency conversion. On my most recent credit card bill, foreign currency transactions show an exchange rate with 10 digits of precision.


Replies

adrian_b • yesterday at 5:20 PM

When implementing currency with integers, actually with fixed-point numbers, there is no difficulty in having an exchange rate with the same precision as the integer format, i.e. up to 18-19 digits for 64-bit integers.

You just have to implement the conversion function carefully, i.e. the exchange ratio would actually be represented not by a single number, but by a ratio of suitable integers, to ensure no loss of precision during the conversion done by exact multiplication with extended double-word result and then division.