A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/c-sharp/decimal-subtract-method-in-c-sharp/ below:

Decimal.Subtract() Method in C# - GeeksforGeeks

Decimal.Subtract() Method in C#

Last Updated : 11 Jul, 2025

This method is used to subtract the one specified Decimal value from another.

Syntax: public static decimal Subtract (decimal a1, decimal a2); Parameters: a1: This parameter specifies the minuend. a2: This parameter specifies the subtrahend. Return Value: Result of subtracting a2 from a1.
Exceptions:

This method will give

OverflowException

if the return value is less than

MinValue

or greater than

MaxValue

. Below programs illustrate the use of the above-discussed method:

Example 1: csharp
// C# program to demonstrate the
// Decimal.Subtract(Decimal, Decimal)
// Method
using System;

class GFG {

    // Main Method
    public static void Main()
    {
        try {

            // Declaring the decimal
            // variables
            Decimal a1 = .01m;
            Decimal a2 = .03m;

            // Subtracting the two Decimal value
            // using Subtract() method
            Decimal value = Decimal.Subtract(a1, a2);

            // Display the Result
            Console.WriteLine("Result is : {0}",
                                         value);
        }

        catch (OverflowException e) {
            Console.Write("Exception Thrown: ");
            Console.Write("{0}", e.GetType(), e.Message);
        }
    }
}
Output:
Result is : -0.02
Example 2:

For

OverflowException csharp
// C# program to demonstrate the
// Decimal.Subtract(Decimal, Decimal)
// Method
using System;

class GFG {

    // Main Method
    public static void Main()
    {
        try {

            // Declaring the decimal variables
            Decimal a1 = Decimal.MinValue;
            Decimal a2 = Decimal.MaxValue;

            // Subtracting the two Decimal value
            // using Subtract() method;
            Decimal value = Decimal.Subtract(a1, a2);

            // Display the Result
            Console.WriteLine("Result is : {0}",
                                        value);
        }

        catch (OverflowException e) 
        {
            Console.Write("Exception Thrown: ");
            Console.Write("{0}", e.GetType(), e.Message);
        }
    }
}
Output:
Exception Thrown: System.OverflowException
Reference:

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4