Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anyone know of a money type in .NET?

Tags:

Does anyone know of an already implemented money type for the .NET framework that supports i18n (currencies, formatting, etc)? I have been looking for a well implemented type and can't seem to find one.

like image 346
Mateo Avatar asked Nov 08 '08 03:11

Mateo


People also ask

What is the datatype for money in C#?

The best datatype to use for currency in C# is decimal. The decimal type is a 128-bit data type suitable for financial and monetary calculations. The decimal type can represent values ranging from 1.0 * 10^-28 to approximately 7.9 * 10^28 with 28-29 significant digits.

How to apply currency format in c#?

The "C" (or currency) format specifier is used to convert a number to a string representing a currency amount. Let us see an example. double value = 139.87; Now to display the above number until three decimal places, use (“C3”) currency format specifier.

Which built in C# data type is the most precise numeric type and thus useful for storing values such as money?

The decimal keyword indicates a 128-bit data type. Compared to floating-point types, the decimal type has more precision and a smaller range, which makes it appropriate for financial and monetary calculations.


2 Answers

Check this article A Money type for the CLR

A convenient, high-performance money structure for the CLR which handles arithmetic operations, currency types, formatting, and careful distribution and rounding without loss.

like image 52
jfs Avatar answered Sep 20 '22 13:09

jfs


I think you want to use the decimal data type, and use the appropriate overload for ToString().

CultureInfo current  = CultureInfo.CurrentCulture;
decimal myMoney = 99.99m;

//formats as money in current culture, like $99.99
string formattedMoney = myMoney.ToString("C", current); 
like image 39
Jason Jackson Avatar answered Sep 19 '22 13:09

Jason Jackson