Decimal class final
A finite base-ten value, independent of binary floating point.
Equal values have identical normalized coefficients and scales. The range matches finite unconstrained PostgreSQL NUMERIC: at most 131072 integer digits and 16383 fractional digits. This does not retain display precision.
- Implemented types
Constructors
- Decimal.fromBigInt(BigInt coefficient, {int scale = 0})
-
Creates coefficient × 10^(-scale), normalizing trailing zeroes.
factory
- Decimal.fromFraction(BigInt numerator, BigInt denominator, {required int scale, DecimalRounding rounding = DecimalRounding.exact})
-
Converts an integer fraction to a finite decimal at an explicit scale.
Only the rounded result must fit the finite Decimal range.
factory
- Decimal.parse(String source)
-
Parses finite decimal text, including scientific notation.
factory
Properties
- coefficient → BigInt
-
Normalized integer significand, without trailing decimal zeroes.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scale → int
-
Decimal exponent divisor: the value equals coefficient × 10^(-scale).
final
Methods
-
compareTo(
Decimal other) → int -
Compares this object to another object.
override
-
constrained(
int precision, int scale) → Decimal - PostgreSQL-style column coercion: round ties away from zero, then check precision. Expression result codecs do not inherit column constraints.
-
divide(
Decimal other, {required int scale, DecimalRounding rounding = DecimalRounding.exact}) → Decimal -
Divides to
scalefractional digits (negative scales round integer digits). The default rejects a result requiring rounding, including repeating ratios. -
fits(
int precision, int scale) → bool - Whether the value already fits a NUMERIC column without rounding.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
rounded(
int scale, {DecimalRounding rounding = DecimalRounding.exact}) → Decimal - Rounds to an explicit scale; the default rejects lost precision.
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator *(
Decimal other) → Decimal - Multiplies exactly and checks the supported result range.
-
operator +(
Decimal other) → Decimal - Adds two exact values and checks the supported result range.
-
operator -(
Decimal other) → Decimal -
Subtracts
otherwithout rounding. -
operator <(
Decimal other) → bool - Compares exact numeric values, independent of their stored scale.
-
operator <=(
Decimal other) → bool -
Whether this exact value is less than or equal to
other. -
operator ==(
Object other) → bool -
The equality operator.
override
-
operator >(
Decimal other) → bool -
Whether this exact value is greater than
other. -
operator >=(
Decimal other) → bool -
Whether this exact value is greater than or equal to
other. -
operator unary-(
) → Decimal - Returns the exact additive inverse.
Static Methods
-
tryParse(
String source) → Decimal? - Parses finite decimal text, returning null for invalid or out-of-range input.
-
validateDigits(
int precision, int scale) → void - Validates PostgreSQL-style column precision and scale declarations.
-
validateScale(
int scale) → void - Throws RangeError if a result scale exceeds the supported finite range.
Constants
- maxFractionDigits → const int
- Maximum count of digits to the right of the decimal point.
- maxIntegerDigits → const int
- Maximum count of digits to the left of the decimal point.