What's the second minimum value that a decimal can represent?

.net, c#, decimal

Solution

The second-minimum value is `Decimal.MinValue + 1`.

This can be inferred from the documentation for `decimal`:

A decimal number is a floating-point value that consists of a sign, a numeric value where each digit in the value ranges from 0 to 9, and a scaling factor that indicates the position of a floating decimal point that separates the integral and fractional parts of the numeric value.

The binary representation of a Decimal value consists of a 1-bit sign, a 96-bit integer number, and a scaling factor used to divide the 96-bit integer and specify what portion of it is a decimal fraction. The scaling factor is implicitly the number 10, raised to an exponent ranging from 0 to 28. Therefore, the binary representation of a Decimal value is of the form, ((-2^96 to 2^96) / 10^(0 to 28)), where -2^96-1 is equal to MinValue, and 2^96-1 is equal to MaxValue.

From the above we can infer that on the extreme edges of the legal value range, the scaling factor is `1` (10 to the power 0) and therefore that's the smallest quantum when a decimal value is modified.

Live proof.

Problem

What's the second minimum value that a `decimal` can represent? That is the value which is larger than `Decimal.MinValue` and smaller than any other values that a `decimal` can represent. How can I obtain this value in C#? Thanks!

Original source