BigDecimal class
A wrapper class for precise decimal arithmetic.
This class provides arbitrary precision decimal arithmetic similar to Java's BigDecimal. It uses Dart's built-in support for arbitrary precision integers and implements decimal arithmetic on top of it.
Example usage:
BigDecimal a = BigDecimal("123.456");
BigDecimal b = BigDecimal("78.9");
BigDecimal sum = a + b;
print(sum.toString()); // "202.356"
print(sum.setScale(2)); // "202.36" (rounded)
- Implemented types
Constructors
- BigDecimal(String value)
-
Creates a BigDecimal from a string representation.
factory
- BigDecimal.fromDouble(double value)
-
Creates a BigDecimal from a double value.
factory
- BigDecimal.fromInt(int value)
-
Creates a BigDecimal from an integer value.
factory
Properties
- hashCode → int
-
Returns the hash code for this BigDecimal.
no setteroverride
- precision → int
-
Returns the precision (total number of digits).
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scale → int
-
Returns the scale (number of digits after decimal point).
no setter
- unscaledValue → BigInt
-
Returns the unscaled value as a BigInt.
no setter
Methods
-
abs(
) → BigDecimal - Returns the absolute value of this BigDecimal.
-
compareTo(
BigDecimal other) → int -
Compares this BigDecimal with another.
override
-
divide(
BigDecimal other, [int? resultScale]) → BigDecimal - Divides this BigDecimal by another.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setScale(
int newScale) → BigDecimal - Returns a BigDecimal with the specified scale.
-
toDouble(
) → double - Converts to double (may lose precision).
-
toString(
) → String -
Returns a string representation of this BigDecimal.
override
Operators
-
operator *(
BigDecimal other) → BigDecimal - Multiplies this BigDecimal by another.
-
operator +(
BigDecimal other) → BigDecimal - Adds another BigDecimal to this one.
-
operator -(
BigDecimal other) → BigDecimal - Subtracts another BigDecimal from this one.
-
operator <(
BigDecimal other) → bool - Comparison operators
-
operator <=(
BigDecimal other) → bool -
operator ==(
Object other) → bool -
Returns true if this BigDecimal equals the specified object.
override
-
operator >(
BigDecimal other) → bool -
operator >=(
BigDecimal other) → bool -
operator unary-(
) → BigDecimal - Returns the negation of this BigDecimal.
Static Properties
- ONE → BigDecimal
-
This creates a BigDecimal with value 1.
final
- TEN → BigDecimal
-
This creates a BigDecimal with value 10.
final
- ZERO → BigDecimal
-
This creates a BigDecimal with value 0.
final