parse method
Implementation
@override
Decimal? parse(String? value) {
if (value.isNullOrBlank) return null;
bool isNegative = value!.trim().startsWith('-');
String newValue = value.replaceAll('-', '');
int sepPos = newValue.indexOf(decimalSeparator);
String integerPart = '0';
String decimalPart = '0';
if (sepPos < 0) {
integerPart = super.strip(newValue)!;
} else if (sepPos == 0) {
decimalPart = super.strip(newValue)!;
} else {
integerPart = super.strip(newValue.substring(0, sepPos))!;
decimalPart = super.strip(newValue.substring(sepPos))!;
}
if (decimalPart.length > precision) {
decimalPart = decimalPart.substring(0, precision);
}
String str = '${isNegative ? '-' : ''}$integerPart.$decimalPart';
return Decimal(precision: precision, doubleValue: double.parse(str));
}