mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-28 14:39:38 +00:00
26 lines
596 B
Dart
26 lines
596 B
Dart
|
import 'package:intl/intl.dart';
|
||
|
|
||
|
const ethereumAmountLength = 12;
|
||
|
const ethereumAmountDivider = 1000000000000;
|
||
|
final ethereumAmountFormat = NumberFormat()
|
||
|
..maximumFractionDigits = ethereumAmountLength
|
||
|
..minimumFractionDigits = 1;
|
||
|
|
||
|
class EthereumFormatter {
|
||
|
static int parseEthereumAmount(String amount) {
|
||
|
try {
|
||
|
return (double.parse(amount) * ethereumAmountDivider).round();
|
||
|
} catch (_) {
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static double parseEthereumAmountToDouble(int amount) {
|
||
|
try {
|
||
|
return amount / ethereumAmountDivider;
|
||
|
} catch (_) {
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
}
|