BigDecimal.fromInt constructor

BigDecimal.fromInt(
  1. int value
)

Creates a BigDecimal from an integer value.

value the integer value

Note: This is equivalent to BigDecimal.fromDouble(value.toDouble()).

BigDecimal a = BigDecimal.fromInt(42);
print(a); // "42"

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)

Implementation

factory BigDecimal.fromInt(int value) {
  return BigDecimal._(BigInt.from(value), 0);
}