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