big_dec 0.1.2+12 copy "big_dec: ^0.1.2+12" to clipboard
big_dec: ^0.1.2+12 copied to clipboard

A library for big calculations.

BigDec #

A library for big calculations.
Hecho en Puerto Rico por Radamés J. Valentín Reyes
Co-engineered by Copilot and Gemini

Note: This library uses high-performance Uint64List limb storage to handle arbitrary-precision calculations (defaulting to 200+ decimal places) with significantly reduced heap overhead.

Import #

import 'package:big_dec/big_dec.dart';

Constructors & Parsers #

You can now convert from standard Dart types directly into BigDec while maintaining a specific precision cap.

From BigInt #

BigInt largeInt = BigInt.parse("12345678901234567890");
BigDec bigDec = BigDec.fromBigInt(largeInt, precision: 200);

From Int #

BigDec bigDec = BigDec.fromInt(42, precision: 200);

From Double #

BigDec bigDec = BigDec.fromDouble(3.14159, precision: 200);

From String #

BigDec bigDec = BigDec.fromString("1.23456789");

Addition #

BigDec bigDec1 = BigDec.fromString("1.5");
BigDec bigDec2 = BigDec.fromString("1.5");
BigDec result = bigDec1.add(bigDec2);
print(result.toStringAsFixed(0));

Subtraction #

BigDec bigDec1 = BigDec.fromString("3.36");
BigDec bigDec2 = BigDec.fromString("1.5");
BigDec result = bigDec1.subtract(bigDec2);
print(result.toStringAsFixed(4));

Multiplication #

BigDec bigDec1 = BigDec.fromString("1.5");
BigDec bigDec2 = BigDec.fromString("3");
BigDec result = bigDec1.multiply(bigDec2);
print(result.toStringAsFixed(4));

Division #

BigDec bigDec1 = BigDec.fromString("1");
bigDec1.setDecimalPrecision(100);
BigDec bigDec2 = BigDec.fromString("3");
BigDec result = bigDec1.divide(bigDec2);
print(result.toStringAsFixed(100));

Decimal Precision #

Set a new decimal precision. Subsequent operations will adhere to this precision cap.

BigDec bigDec1 = BigDec.fromString("1");
BigDec updated = bigDec1.setDecimalPrecision(200);

Rounding & Truncation #

BigDec bigDec1 = BigDec.fromString("1.5");

// Round
BigDec rounded = bigDec1.round();

// Floor
BigDec floorVal = bigDec1.floor();

// Ceil
BigDec ceilVal = bigDec1.ceil();

Absolute Value #

BigDec bigDec1 = BigDec.fromString("-25");
BigDec result = bigDec1.abs();
print(result.toString());

Power #

BigDec bigDec1 = BigDec.fromString("25");
BigDec result = bigDec1.pow(BigInt.from(4));
print(result.toString());

Square Root #

BigDec bigDec1 = BigDec.fromString("25");
BigDec result = bigDec1.sqrt();
print(result.toString());

Component Getters #

Access the underlying magnitude components as BigInt.

BigDec bigDec1 = BigDec.fromString("123.456");
print(bigDec1.integer); // 123
print(bigDec1.decimal); // 456

String Formatting #

BigDec bigDec1 = BigDec.fromString("1.23456789");
print(bigDec1.toStringAsFixed(2)); // 1.23
0
likes
0
points
76
downloads

Publisher

unverified uploader

Weekly Downloads

A library for big calculations.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on big_dec