Skip to content

Commit

Permalink
Fix the extractDecimals extension method to handle zero decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
vilkris4 committed Sep 3, 2023
1 parent a6b5fcb commit fbf8c94
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/utils/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ extension StringExtensions on String {

BigInt extractDecimals(int decimals) {
if (!contains('.')) {
if (decimals == 0 && isEmpty) {
return BigInt.zero;
}
return BigInt.parse(this + ''.padRight(decimals, '0'));
}
List<String> parts = split('.');
Expand All @@ -19,7 +22,6 @@ extension StringExtensions on String {
? parts[1].substring(0, decimals)
: parts[1].padRight(decimals, '0')));
}
//BigInt.parse(num.parse(this).toStringAsFixed(decimals).replaceAll('.', ''));

String abs() => this;
}
Expand Down

0 comments on commit fbf8c94

Please sign in to comment.