Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Money data type for .NET?

People also ask

What data type is used for money?

Unlike the DECIMAL data type, the MONEY data type is always treated as a fixed-point decimal number. The database server defines the data type MONEY(p) as DECIMAL(p,2). If the precision and scale are not specified, the database server defines a MONEY column as DECIMAL(16,2).

Which choice is the best data type for working with money?

1 Answer. Java has Currency class that represents the ISO 4217 currency codes. BigDecimal is the best type for representing currency decimal values.

Is currency a data type in Excel?

Data Types are a special kind of data in Excel with properties that can be accessed like fields. Example Data Types include Stocks, Geography, and Currency.


Martin Fowler considers money as a special case of "Quantity", secondly he thinks the right Data Type for money should be the Big Integer. And he does have a point.

Quantity and Money Pattern by Martin Fowler


NodaMoney provides a library that treats Money as a first class citizen in .NET and handles all the ugly bits like currencies and formatting.

It complies with the currencies in ISO 4217. And it's the .NET counterpart of the java library JodaMoney.


Money Data Type @ The Code Project

http://www.codeproject.com/KB/vb/moneyDatatype.aspx

Author states similar problem:

as part of a recent application I realized how lacking .NET is for currency support, don't get me wrong, there are many "pieces" but the glue for all items is missing, so this article is a response to that.

and fulfills objectives

my main objectives became

  • Store the currency type with the value (i.e. AUD, US, DKK).
  • Store formatting details (i.e. decimal grouping, currency symbols, etc.).
  • Conversion providers, I didn't want to hard code this as it is a datatype and not a solution.
  • Development safety features (i.e. prevent arithmetic on different currency types).

So far this the closest .NET code to what I'm searching for. It fulfills most requirements of Money.

If anybody has something better it would be much appreciated.


you will probably find that creating your own class will result in the best solution.


If you are looking for patterns, you could check out Joda Money. It is Java, but should give you some ideas on an API. A C# implementation would be much less verbose due to operator overloading.


Have a look here:

http://blogs.msdn.com/lucabol/archive/2008/12/04/financial-functions-for-net-released.aspx

It provides a .NET library replicating all the excel financial functions.

Doing currency conversion is tricky, because obviously it changes continously, so hardcoded values will be more or less useless. However, you may be able to use a web service to access up-to-date exchange rates. This one looks like a good start. Even better, a REST-style interface to the same converter:

http://www.webservicex.com/CurrencyConvertor.asmx/ConversionRate?FromCurrency=GBP&ToCurrency=EUR

So that outputs the conversion rate of pounds sterling to euros.