suhair
suhair

Reputation: 10929

Which data type in c# is better suited for currency calculations?

And also the better counter part in sql server for mapping.

Upvotes: 2

Views: 1642

Answers (2)

John Leidegren
John Leidegren

Reputation: 60987

System.Decimal or 'decimal' is a 128-bit data type. Compared to floating-point types, the decimal type has a greater precision and a smaller range, which makes it suitable for financial and monetary calculations.

If you want a numeric real literal to be treated as decimal, use the suffix m or M:

decimal amount = 300.5m;
var dec = 300.5M; // same as above

The decimal is implemented in the CLR and is guaranteed to return the same result regardless of hardware.

JaredPar is right!

Upvotes: 3

Related Questions