toDecimal property

Decimal get toDecimal

Converts the string to a Decimal. Returns null if the conversion fails. Requires the decimal package.

Example:

print('123.45'.toDecimal); // Output: Decimal(123.45) assuming decimal is implemented
print('abc'.toDecimal); // Output: 0

Implementation

Decimal get toDecimal => Decimal.tryParse(this) ?? Decimal.zero;