toSats method
assumes the string is an amount
Implementation
int toSats([int divisibility = 8]) {
String x = trim();
if (x == '' || x == '.') {
return 0;
}
if (!x.contains('.')) {
x = '$x.';
}
final List<String> s = x.split('.');
if (s.length > 2) {
return 0;
}
if (s.last.length > divisibility) {
s[1] = s[1].substring(0, divisibility);
} else if (s.last.length < divisibility) {
s[1] = s[1] + '0' * (divisibility - s.last.length);
}
final String textSats = '${s.first}${s.last}';
if (textSats.length > 19) {
return int.parse(textSats.substring(0, 19));
}
return int.parse(textSats);
}