Decimal type in C#



The decimal type is a value type and has the plus, minus, multiply and divide operators.

Firstly, set two decimal values ?

decimal d1 = 5.8M;
decimal d2 = 3.2M;

To add decimals ?

d1 = d1 + d2;

Let us see an example to add two decimal values ?

Example

Live Demo

using System;
using System.Linq;
class Demo {
   static void Main() {
      decimal d1 = 5.8M;
      decimal d2 = 3.2M;
      d1 = d1 + d2;
      Console.WriteLine(d1);
   }
}

Output

9.0
Updated on: 2025-06-05T09:58:40+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements