Struct BigDecimal
Arbitrary-precision signed decimal, the CEL Decimal backing type for this client and
the unscaled/scale representation used by the Variant codec.
A value is unscaled × 10^(-scale) — a BigInteger unscaled
value and an int scale, exactly like Java's
java.math.BigDecimal. .NET's decimal tops out at 28–29
significant digits; parity with the other Schema Registry clients (Java/Go/Python/
JS/Rust) requires the 38-significant-digit division and square root those clients
produce, so the arithmetic here mirrors Java's MathContext(38, HALF_UP).
Assembly: Confluent.SchemaRegistry.dll
Syntax
public readonly struct BigDecimal : IComparable<BigDecimal>, IEquatable<BigDecimal>
Constructors
BigDecimal(BigInteger, int)
Declaration
public BigDecimal(BigInteger unscaled, int scale)
Parameters
Fields
SaneCoefficient
A far tighter ceiling on what can be encoded, which bounds a different
resource.
Declaration
public const int SaneCoefficient = 4300
Field Value
SaneWidth
The width ceiling for a computation, in decimal digits.
Declaration
public const int SaneWidth = 10000000
Field Value
Zero
Declaration
public static readonly BigDecimal Zero
Field Value
Properties
Scale
Number of fractional digits (negative means trailing integer zeros).
Declaration
public int Scale { get; }
Property Value
Signum
-1, 0 or 1 as the value is negative, zero or positive.
Declaration
public int Signum { get; }
Property Value
Unscaled
Unscaled two's-complement integer value.
Declaration
public BigInteger Unscaled { get; }
Property Value
Methods
Abs()
Declaration
Returns
Add(BigDecimal)
Declaration
public BigDecimal Add(BigDecimal other)
Parameters
Returns
CompareTo(BigDecimal)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
Declaration
public int CompareTo(BigDecimal other)
Parameters
| Type |
Name |
Description |
| BigDecimal |
other |
An object to compare with this instance.
|
Returns
| Type |
Description |
| int |
A value that indicates the relative order of the objects being compared. The return value has these meanings:
| Value | Meaning |
|---|
| Less than zero | This instance precedes other in the sort order. | | Zero | This instance occurs in the same position in the sort order as other. | | Greater than zero | This instance follows other in the sort order. |
|
Divide(BigDecimal)
Division at Confluent.SchemaRegistry.BigDecimal.DivisionPrecision significant digits with HALF_UP
rounding — Java divide(divisor, MathContext(38, HALF_UP)). A result that
terminates within the precision keeps its exact (trailing-zero-stripped) value;
a non-terminating result is rounded to 38 significant digits.
Declaration
public BigDecimal Divide(BigDecimal divisor)
Parameters
Returns
Equals(BigDecimal)
Numeric equality (ignores scale), matching decimals.eq.
Declaration
public bool Equals(BigDecimal other)
Parameters
Returns
Equals(object)
Indicates whether this instance and a specified object are equal.
Declaration
public override bool Equals(object obj)
Parameters
| Type |
Name |
Description |
| object |
obj |
The object to compare with the current instance.
|
Returns
| Type |
Description |
| bool |
true if obj and this instance are the same type and represent the same value; otherwise, false.
|
Overrides
FromBigInteger(BigInteger)
Declaration
public static BigDecimal FromBigInteger(BigInteger value)
Parameters
Returns
FromDecimal(decimal)
Lossless conversion from a decimal, built directly from its bits so
that scale and trailing zeros are preserved (1.50m becomes scale 2).
Declaration
public static BigDecimal FromDecimal(decimal value)
Parameters
| Type |
Name |
Description |
| decimal |
value |
|
Returns
FromDouble(double)
Convert a double the way Java's BigDecimal.valueOf(double)
does: via the shortest decimal string that round-trips to the same double, not
the exact binary value. .NET's round-trip ("R") format is that shortest string.
Declaration
public static BigDecimal FromDouble(double value)
Parameters
| Type |
Name |
Description |
| double |
value |
|
Returns
FromFloat(float)
A BigDecimal from a float, via the shortest decimal
string that round-trips to the same float — Java Float.toString. A whole-number
value keeps a trailing .0 (scale 1), matching Java/Python and the other clients.
Declaration
public static BigDecimal FromFloat(float value)
Parameters
| Type |
Name |
Description |
| float |
value |
|
Returns
FromLong(long)
Declaration
public static BigDecimal FromLong(long value)
Parameters
| Type |
Name |
Description |
| long |
value |
|
Returns
GetHashCode()
Returns the hash code for this instance.
Declaration
public override int GetHashCode()
Returns
| Type |
Description |
| int |
A 32-bit signed integer that is the hash code for this instance.
|
Overrides
Max(BigDecimal)
Declaration
public BigDecimal Max(BigDecimal other)
Parameters
Returns
Min(BigDecimal)
Declaration
public BigDecimal Min(BigDecimal other)
Parameters
Returns
Multiply(BigDecimal)
Declaration
public BigDecimal Multiply(BigDecimal other)
Parameters
Returns
Negate()
Declaration
public BigDecimal Negate()
Returns
Parse(string)
Parse a decimal string, accepting an optional sign, an optional fractional
part, and optional scientific-notation exponent — the same grammar as Java's
new BigDecimal(String).
Declaration
public static BigDecimal Parse(string s)
Parameters
| Type |
Name |
Description |
| string |
s |
|
Returns
Remainder(BigDecimal)
Remainder with the sign of the dividend — Java BigDecimal.remainder,
matching SQL MOD. Throws on a zero divisor.
Declaration
public BigDecimal Remainder(BigDecimal divisor)
Parameters
Returns
RequireSaneWidth(long, string, string, int)
Refuses a positional form too wide to build.
Declaration
public static void RequireSaneWidth(long needed, string fn, string what, int limit = 10000000)
Parameters
SetScale(int, Rounding)
Return the value at newScale fractional digits, rounding
with mode — Java setScale(newScale, mode).
Declaration
public BigDecimal SetScale(int newScale, BigDecimal.Rounding mode)
Parameters
Returns
Sqrt()
Square root at Confluent.SchemaRegistry.BigDecimal.DivisionPrecision significant digits, HALF_UP —
Java sqrt(MathContext(38, HALF_UP)). Throws on a negative value.
Declaration
Returns
Subtract(BigDecimal)
Declaration
public BigDecimal Subtract(BigDecimal other)
Parameters
Returns
ToDecimal()
Nearest decimal (may lose precision). Throws
OverflowException when the integer part does not fit in a
decimal — Java toBigDecimal narrowed to System.Decimal.
Declaration
public decimal ToDecimal()
Returns
ToDouble()
Nearest double (may lose precision; ±Infinity out of range) —
Java doubleValue.
Declaration
Returns
ToPlainString()
Plain decimal string with no scientific notation — Java toPlainString.
Declaration
public string ToPlainString()
Returns
ToString()
Returns the fully qualified type name of this instance.
Declaration
public override string ToString()
Returns
| Type |
Description |
| string |
The fully qualified type name.
|
Overrides
UnscaledPrecision(BigInteger)
The digit count of an unscaled value, which is what BigDecimal.precision()
reports and what confluent.type.Decimal.precision carries. Zero is 1
there, never 0.
Declaration
public static uint UnscaledPrecision(BigInteger unscaled)
Parameters
Returns
Implements
Extension Methods