Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing and mapping currency exchange rates

I need to store on SQLServer 2008 R2 currency exchange rate data.

The application making use of this data is developed in C#. The column holding the currency exchange rate will be required to store conversions both ways-- meaning, I'd rather have a fixed precision but a variable scale.

What Data type should I choose on SQL Server that can be mapped to C# avoiding any data loss? I'm looking at MSDN supplied mappings matrix and I'm can't seem to find anything that I can safely handle.

  • Float(53) could be a possibility, but floats are approximate values.
  • Money are only accurate to the ten thousandth of the unit

I'm left with Decimal. However these offer fixed scales. And that's where I'm stumped:

If I'm required to store a number like 0.0104182 but also 123.673, I've established a precision of 10 as my requirement. But how should I set a scale that can fully accommodate this precision?

like image 948
Alexandre Bell Avatar asked Jun 29 '11 22:06

Alexandre Bell


1 Answers

For exchange rates I'd use decimal (19, 9) or so.

You have to allow for "telephone number" rates

Examples, at current rates 1 British Pound is

  • 13,835.87699 Indonesian Rupiah
  • 33,016.24786 Vietnamese Dong
like image 57
gbn Avatar answered Sep 21 '22 03:09

gbn