Decimal class

Decimal

var a = Decimal.parse("12.34");
var b = Decimal.fromInt(5);
var c = a + b; // 17.34
var d = a / Decimal.parse("3"); // 867/25 (Rational representation)
var e = d.withScale(2, RoundingMode.halfUp); // 34.68
Implemented types
Implementers

Constructors

Decimal(BigInt _value, int _scale)
Decimal.fraction(BigInt numerator, BigInt denominator)
factory
Decimal.fromInt(int value)
factory
Decimal.intFraction(int numerator, int denominator)
factory
Decimal.parse(String value)
Parse from string
factory

Properties

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
no setter

Methods

abs() Decimal
Absolute value
compareTo(Decimal other) int
Compare two Decimals
NOTES:
override
divide(Decimal other, {int? scale, RoundingMode? mode}) Decimal
halfUp(int scale) Decimal
Rounds to specified scale using half-up rounding mode
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
strictEquals(Decimal other) bool
Strict equality check (including scale)
toBigInt() BigInt
Convert to BigInt (truncating decimal part)
toDouble() double
Convert to double (may lose precision)
toInt() int
Convert to int (truncating decimal part)
toRational() Rational
toString() String
Convert to plain string representation.
Examples:
override
withScale(int scale, RoundingMode mode) Decimal
Convert to Decimal with specified scale and rounding mode

Operators

operator *(Decimal other) Decimal
Multiplication
operator +(Decimal other) Decimal
Addition
operator -(Decimal other) Decimal
Subtraction
operator /(Decimal other) Decimal
Division, may return Rational if not exact decimal
Examples:
operator <(Decimal other) bool
Less than
operator <=(Decimal other) bool
Less than or equal to
operator ==(Object other) bool
Equal to
override
operator >(Decimal other) bool
Greater than
operator >=(Decimal other) bool
Greater than or equal to
operator unary-() Decimal
Negation

Static Properties

one Decimal
One without decimal places "1"
final
zero Decimal
Zero without decimal places "0"
final