Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C# Data Types
  • C# Decision Making
  • C# Methods
  • C# Delegates
  • C# Constructors
  • C# Arrays
  • C# ArrayList
  • C# String
  • C# Tuple
  • C# Indexers
  • C# Interface
  • C# Multithreading
  • C# Exception
Open In App
Next Article:
C# | SByte Struct Fields
Next article icon

C# Decimal Struct

Last Updated : 31 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In C#, the Decimal Struct class represents a decimal floating-point number. Due to its wide range, it is generally used for financial calculations that require large numbers of significant integral and fractional digits and no round-off errors. We can perform the mathematical operations on Decimal type like addition, subtraction, division, multiplication, etc.

Range of Decimal Number: +79,228,162,514,264,337,593,543,950,335 to -79,228,162,514,264,337,593,543,950,335.

Example: Demonstration of Storing large Values using Decimal Struct

C#
using System;  public class Geeks {     static public void Main ()     {        // Storing Large Values        decimal price = 99.99m;      decimal largeNum = 7922816251426433759354335m;     Console.WriteLine(price);     Console.WriteLine(largeNum);         } } 

Output
99.99 7922816251426433759354335 

Constructors

Constructors

Description

Decimal(Double)

Initializes a new instance of Decimal to the value of the specified double-precision floating-point number.

Decimal(Int32)

Initializes a new instance of Decimal to the value of the specified 32-bit signed integer.

Decimal(Int32[])

Initializes a new instance of Decimal to a decimal value represented in binary and contained in a specified array.

Decimal(Int64)

Initializes a new instance of Decimal to the value of the specified 64-bit signed integer.

Decimal(Single)

Initializes a new instance of Decimal to the value of the specified single-precision floating-point number.

Decimal(UInt32)

Initializes a new instance of Decimal to the value of the specified 32-bit unsigned integer.

Decimal(UInt64)

Initializes a new instance of Decimal to the value of the specified 64-bit unsigned integer.

Decimal(Int32, Int32, Int32, Boolean, Byte)

Initializes a new instance of Decimal from parameters specifying the instance’s constituent parts.

Example:

C#
// Using Decimal Constructor using System;  class Geeks {     static void Main()     {         // Creating a decimal using the constructor         decimal value = new decimal(12345.6789);                  // Displaying the value         Console.WriteLine("Decimal Value: " + value);     } } 

Output
Decimal Value: 12345.6789 

Fields

Fields

Description

MaxValue

Represents the largest possible value of Decimal. This field is constant and read-only.

MinusOne

Represents the number negative one (-1).

MinValue

Represents the smallest possible value of Decimal. This field is constant and read-only.

One

Represents the number one (1).

Zero

Represents the number zero (0).

Example:

C#
// C# program to illustrate the  // use of MaxValue and MinValue field  using System;   public class Geeks {  	static public void Main()  	{   		// Display the Minimum and Maximum values  		Console.WriteLine("Display Maximum value "+  		"of Decimal: {0}", Decimal.MaxValue);   		Console.WriteLine("Display Minimum value of "+  		"Decimal: {0}", Decimal.MinValue);  	}  }  

Output
Display Maximum value of Decimal: 79228162514264337593543950335 Display Minimum value of Decimal: -79228162514264337593543950335 

Methods

Method

Description

Add(Decimal, Decimal)

Adds two specified Decimal values.

Ceiling(Decimal)

Returns the smallest integral value that is greater than or equal to the specified decimal number.

Compare(Decimal, Decimal)

Compares two specified Decimal values.

CompareTo()

Compares this instance to a specified object or Decimal and returns an indication of their relative values.

Divide(Decimal, Decimal)

Divides two specified Decimal values.

Equals()

Returns a value indicating whether two instances of Decimal represent the same value.

Floor(Decimal)

Rounds a specified Decimal number to the closest integer toward negative infinity.

FromOACurrency(Int64)

Converts the specified 64-bit signed integer, which contains an OLE Automation Currency value, to the equivalent Decimal value.

GetBits(Decimal)

Converts the value of a specified instance of Decimal to its equivalent binary representation.

GetHashCode()

Returns the hash code for this instance.

GetTypeCode()

Returns the TypeCode for value type Decimal.

Multiply(Decimal, Decimal)

Multiplies two specified Decimal values.

Negate(Decimal)

Returns the result of multiplying the specified Decimal value by a negative one.

Parse()

Converts the string representation of a number to its Decimal equivalent.

Remainder(Decimal, Decimal)

Computes the remainder after dividing two Decimal values.

Round()

Rounds a value to the nearest integer or specified number of decimal places.

Subtract(Decimal, Decimal)

Subtracts one specified Decimal value from another.

ToByte(Decimal)

Converts the value of the specified Decimal to the equivalent 8-bit unsigned integer.

ToDouble(Decimal)

Converts the value of the specified Decimal to the equivalent double-precision floating-point number.

ToInt16(Decimal)

Converts the value of the specified Decimal to the equivalent 16-bit signed integer.

ToInt32(Decimal)

Converts the value of the specified Decimal to the equivalent 32-bit signed integer.

ToInt64(Decimal)

Converts the value of the specified Decimal to the equivalent 64-bit signed integer.

ToOACurrency(Decimal)

Converts the specified Decimal value to the equivalent OLE Automation Currency value, which is contained in a 64-bit signed integer.

ToSByte(Decimal)

Converts the value of the specified Decimal to the equivalent 8-bit signed integer.

ToSingle(Decimal)

Converts the value of the specified Decimal to the equivalent single-precision floating-point number.

ToString()

Converts the numeric value of this instance to its equivalent String representation.

ToUInt16(Decimal)

Converts the value of the specified Decimal to the equivalent 16-bit unsigned integer.

ToUInt32(Decimal)

Converts the value of the specified Decimal to the equivalent 32-bit unsigned integer.

ToUInt64(Decimal)

Converts the value of the specified Decimal to the equivalent 64-bit unsigned integer.

Truncate(Decimal)

Returns the integral digits of the specified Decimal; any fractional digits are discarded.

TryParse()

Converts the string representation of a number to its Decimal equivalent. A return value indicates whether the conversion succeeded or failed.

Example:

C#
// C# program to illustrate the  // use of Add(Decimal, Decimal) method  using System;   class Geeks  {  	static public void Main()  	{  		// Addition of two Decimal values  		// Using Add() method  		Decimal val1 = 349;  		Decimal val2 = 590;  		Decimal res;  		res = Decimal.Add(val1, val2);   		Console.WriteLine("Addition is: {0}", res);  	}  }  

Output
Addition is: 939 

Operators

Operators

Description

Addition(Decimal, Decimal)

Adds two specified Decimal values.

Decrement(Decimal)

Decrements the Decimal operand by one.

Division(Decimal, Decimal)

Divides two specified Decimal values.

Equality(Decimal, Decimal)

Returns a value that indicates whether two Decimal values are equal.

Explicit(Single to Decimal)

Defines an explicit conversion of a single-precision floating-point number to a Decimal.

Explicit(Double to Decimal)

Defines an explicit conversion of a double-precision floating-point number to a Decimal.

Explicit(Decimal to UInt32)

Defines an explicit conversion of a Decimal to a 32-bit unsigned integer.

Explicit(Decimal to UInt16)

Defines an explicit conversion of a Decimal to a 16-bit unsigned integer.

Explicit(Decimal to Single)

Defines an explicit conversion of a Decimal to a single-precision floating-point number.

Explicit(Decimal to SByte)

Defines an explicit conversion of a Decimal to an 8-bit signed integer.

Explicit(Decimal to UInt64)

Defines an explicit conversion of a Decimal to a 64-bit unsigned integer.

Explicit(Decimal to Int32)

Defines an explicit conversion of a Decimal to a 32-bit signed integer.

Explicit(Decimal to Int16)

Defines an explicit conversion of a Decimal to a 16-bit signed integer.

Explicit(Decimal to Double)

Defines an explicit conversion of a Decimal to a double-precision floating-point number.

Explicit(Decimal to Char)

Defines an explicit conversion of a Decimal to a Unicode character.

Explicit(Decimal to Byte)

Defines an explicit conversion of a Decimal to an 8-bit unsigned integer.

Explicit(Decimal to Int64)

Defines an explicit conversion of a Decimal to a 64-bit signed integer.

GreaterThan(Decimal, Decimal)

Returns a value indicating whether a specified Decimal is greater than another specified Decimal.

GreaterThanOrEqual(Decimal, Decimal)

Returns a value indicating whether a specified Decimal is greater than or equal to another specified Decimal.

Implicit(UInt32 to Decimal)

Defines an implicit conversion of a 32-bit unsigned integer to a Decimal.

Implicit(UInt16 to Decimal)

Defines an implicit conversion of a 16-bit unsigned integer to a Decimal.

Implicit(SByte to Decimal)

Defines an implicit conversion of an 8-bit signed integer to a Decimal.

Implicit(Int64 to Decimal)

Defines an implicit conversion of a 64-bit signed integer to a Decimal.

Implicit(Byte to Decimal)

Defines an implicit conversion of an 8-bit unsigned integer to a Decimal.

Implicit(Int16 to Decimal)

Defines an implicit conversion of a 16-bit signed integer to a Decimal.

Implicit(Char to Decimal)

Defines an implicit conversion of a Unicode character to a Decimal.

Implicit(UInt64 to Decimal)

Defines an implicit conversion of a 64-bit unsigned integer to a Decimal.

Implicit(Byte to Decimal)

Defines an implicit conversion of an 8-bit unsigned integer to a Decimal.

Implicit(Int16 to Decimal)

Defines an implicit conversion of a 16-bit signed integer to a Decimal.

Implicit(Char to Decimal)

Defines an implicit conversion of a Unicode character to a Decimal.

Implicit(UInt64 to Decimal)

Defines an implicit conversion of a 64-bit unsigned integer to a Decimal.

Implicit(Int32 to Decimal)

Defines an implicit conversion of a 32-bit signed integer to a Decimal.

Increment(Decimal)

Increments the Decimal operand by 1.

Inequality(Decimal, Decimal)

Returns a value that indicates whether two Decimal objects have different values.

LessThan(Decimal, Decimal)

Returns a value indicating whether a specified Decimal is less than another specified Decimal.

LessThanOrEqual(Decimal, Decimal)

Returns a value indicating whether a specified Decimal is less than or equal to another specified Decimal.

Modulus(Decimal, Decimal)

Returns the remainder resulting from dividing two specified Decimal values.

Multiply(Decimal, Decimal)

Multiplies two specified Decimal values.

Subtraction(Decimal, Decimal)

Subtracts two specified Decimal values.

UnaryNegation(Decimal)

Negates the value of the specified Decimal operand.

UnaryPlus(Decimal)

Returns the value of the Decimal operand (the sign of the operand is unchanged).

Example:

C#
// C# program to illustrate the  // use of Decrement and Increment operator  using System;   class Geeks  {  	static public void Main()  	{  		Decimal val1 = 1000;  		Decimal val2 = 10000;   		// Using Decrement operator we decrease myval1 by 1  		Console.WriteLine("value 1 is: {0}", val1);  		Console.WriteLine("Decrease val1 by 1:{0}", --val1);  		Console.WriteLine();   		// Using Increment operator we increase myval2 by 1  		Console.WriteLine("value 2 is: {0}", val2);  		Console.WriteLine("Increase val2 by 1:{0}", ++val2);  	}  }  

Output
value 1 is: 1000 Decrease val1 by 1:999  value 2 is: 10000 Increase val2 by 1:10001 


Next Article
C# | SByte Struct Fields
author
ankita_saini
Improve
Article Tags :
  • C#
  • CSharp-Decimal-Struct

Similar Reads

  • C# Int32 Struct
    In C#, the Int32 struct represents a 32-bit signed integer and is commonly used as the int data type. It belongs to the System namespace and provides various methods to perform operations like mathematical computations, parsing, and type conversion. The Int32 struct inherits from ValueType, which in
    3 min read
  • C# Int16 Struct
    In C#, Int16 Struct defined under the System namespace represents a 16-bit signed integer also known as a short datatype etc. We can also call the methods of math class to perform mathematical operations. Int16 struct inherits the ValueType class which inherits the Object class. Characteristics are
    3 min read
  • C# Int 64 Struct
    In C#, the Int64 struct represents a 64-bit signed integer and is commonly used as the long data type. It belongs to the System namespace and provides various methods to perform operations like mathematical computations, parsing, and type conversion. The Int64 struct inherits from ValueType, which i
    3 min read
  • C# Byte Struct
    In C#, Byte Struct is used to represent 8-bit unsigned integers. The Byte is an immutable value type and the range of Byte is from 0 to 255. This class allows us to create Byte data types and we can perform mathematical and bitwise operations on them like addition, subtraction, multiplication, divis
    2 min read
  • C# | SByte Struct Fields
    In C#, Sbyte Struct comes under the System namespace which represents an 8-bit signed integer. The SByte value type represents integers with values ranging from -128 to +127. There are the two fields in the System.SByte Struct as follows: SByte.MaxValue Field SByte.MinValue Field SByte.MaxValue Fiel
    2 min read
  • C# | Structures | Set - 1
    Structure is a value type and a collection of variables of different data types under a single unit. It is almost similar to a class because both are user-defined data types and both hold a bunch of different data types. C# provide the ability to use pre-defined data types. However, sometimes the us
    4 min read
  • C# UInt32 Struct
    In C#, the UInt32 struct represents a 32-bit unsigned integer (commonly referred to as the uint data type). It is defined in the System namespace and provides various methods for mathematical computations, parsing, and type conversion. Because of it is an unsigned type, it only holds non-negative va
    2 min read
  • C# UInt64 Struct
    In C#, the UInt64 struct represents a 64-bit unsigned integer, commonly referred to as the ulong data type. It is defined in the System namespace and provides various methods for mathematical computations, parsing, and type conversion. Since it is an unsigned type, it only holds non-negative values.
    3 min read
  • C# UInt16 Struct
    In C#, the UInt16 struct, defined under the System namespace, represents a 16-bit unsigned integer, commonly referred to as the ushort data type. It does not support negative values and provides a range from 0 to 65,535. The UInt16 struct inherits the ValueType class, which further inherits the Obje
    2 min read
  • C# Data Types
    Data types specify the type of data that a valid C# variable can hold. C# is a strongly typed programming language because in C# each type of data (such as integer, character, float, and so forth) is predefined as part of the programming language and all constants or variables defined for a given pr
    7 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences