Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

decimal
c#
minvalue
communitycreator

What is Decimal.MinValue in C#?

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

Decimal.MinValue is a field in C# that represents the smallest possible value of decimal. It is a constant field and read-only, which means that it cannot be modified.

Syntax

public static readonly decimal MinValue;
Syntax to get minimum value of decimal

Return value

This field returns the value -79,228,162,514,264,337,593,543,950,335.

Code example

// use System
using System;
// create class
class DecimalMinValue
{
// main method
static void Main()
{
// print the field value
Console.WriteLine(Decimal.MinValue);
}
}
Code snippet to show the minimum value of decimal in C#

Explanation

  • Line 11: We print the value of the Decimal.MinValue field to the console.

If there is a decimal value that is less than the Decimal.MinValue, the field will throw an error, as this is the minimum value a decimal can be.

Code example

// use System
using System;
// create class
class DecimalMinValue
{
static void Main()
{
// add to another
// decimal value
decimal newDecimalNumber = -1.0m + Decimal.MinValue;
// print result
Console.WriteLine(newDecimalNumber);
}
}
Any decimal value lesser than the Decimal.MinValue throws an error

Explanation

  • Line 10: We create a decimal variable and initialize it with the sum of -1.0 and Decimal.MinValue. This will throw an error because no decimal value is supposed to be less than the Decimal.MinValue field.

RELATED TAGS

decimal
c#
minvalue
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring