What is the best data type for Currency in C#?

This content was proof-read by Grammarly. You can Try Grammary for FREE

If you are looking at finding out what could be the best data type for currency in C# ?, this post will provide a quick tip or insights on the same.

What is the best data type for Currency in C#?

Use decimal for any currency or money values.

Are you a .NET Developer planning to integrate GraphQL for .NET in your Application? Check out this book BUY & DOWNLOAD GRAPHQL.NET COOKBOOK

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.

Here’s a sample code snippet demonstrating how to use decimal.

public class Hello {
    public static void Main() {
        decimal salary = 75000.50M;
        System.Console.WriteLine("Salary : "  + salary);
%d bloggers like this: