Decimal class

A number that can be exactly written with a finite number of digits in the decimal system.

Implemented types

Constructors

Decimal.fromBigInt(BigInt value)
Create a new Decimal from a BigInt.
factory
Decimal.fromInt(int value)
Create a new Decimal from an int.
factory
Decimal.fromJson(String value)
Create a new Decimal from its String representation.
factory

Properties

hashCode int
The hash code for this object.
no setteroverride
inverse → Rational
Returns a Rational corresponding to 1/this.
no setter
isInteger bool
Returns true if this is an integer.
no setter
precision int
The precision of this Decimal.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scale int
The scale of this Decimal.
no setter
signum int
The signum function value of this.
no setter

Methods

abs() Decimal
Returns the absolute value of this.
ceil({int scale = 0}) Decimal
Returns the least Decimal value that is no smaller than this Rational.
clamp(Decimal lowerLimit, Decimal upperLimit) Decimal
Clamps this to be in the range lowerLimit-upperLimit.
compareTo(Decimal other) int
Compares this object to another object.
override
floor({int scale = 0}) Decimal
Returns the greatest Decimal value no greater than this Rational.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pow(int exponent) → Rational
Returns this to the power of exponent.
remainder(Decimal other) Decimal
Return the remainder from dividing this Decimal by other.
round({int scale = 0}) Decimal
Returns the Decimal value closest to this number.
shift(int value) Decimal
Shift the decimal point on the right for positive value or on the left for negative one.
toBigInt() BigInt
The BigInt obtained by discarding any fractional digits from this.
toDouble() double
Returns this as a double.
toJson() String
Converts this to String by using toString.
toRational() → Rational
The Rational corresponding to this.
toString() String
Returns a String representation of this.
override
toStringAsExponential([int fractionDigits = 0]) String
An exponential string-representation of this number with fractionDigits digits after the decimal point.
toStringAsFixed(int fractionDigits) String
A decimal-point string-representation of this number with fractionDigits digits after the decimal point.
toStringAsPrecision(int precision) String
A string representation with precision significant digits.
truncate({int scale = 0}) Decimal
The BigInt obtained by discarding any fractional digits from this.

Operators

operator %(Decimal other) Decimal
Euclidean modulo operator.
operator *(Decimal other) Decimal
Multiplication operator.
operator +(Decimal other) Decimal
Addition operator.
operator -(Decimal other) Decimal
Subtraction operator.
operator /(Decimal other) → Rational
Division operator.
operator <(Decimal other) bool
Whether this number is numerically smaller than other.
operator <=(Decimal other) bool
Whether this number is numerically smaller than or equal to other.
operator ==(Object other) bool
The equality operator.
override
operator >(Decimal other) bool
Whether this number is numerically greater than other.
operator >=(Decimal other) bool
Whether this number is numerically greater than or equal to other.
operator unary-() Decimal
Returns the negative value of this rational.
operator ~/(Decimal other) BigInt
Truncating division operator.

Static Properties

one Decimal
The Decimal corresponding to 1.
getter/setter pair
ten Decimal
The Decimal corresponding to 10.
getter/setter pair
zero Decimal
The Decimal corresponding to 0.
getter/setter pair

Static Methods

parse(String source) Decimal
Parses source as a decimal literal and returns its value as Decimal.
tryParse(String source) Decimal?
Parses source as a decimal literal and returns its value as Decimal, or null if the parsing fails.