dev
dart 23 lines 527 Bytes
Raw
1 import 'dart:math';
2
3 class EVMChainFormatter {
4 static const int evmDecimals = 18;
5
6 static int parseEVMChainAmount(String amount) {
7 try {
8 return (double.parse(amount) * pow(10, evmDecimals)).round();
9 } catch (_) {
10 return 0;
11 }
12 }
13
14 static String truncateDecimals(String amount, int decimals) {
15 final parts = amount.split(".");
16
17 if (parts.length == 2) {
18 parts[1] = parts[1].substring(0, parts[1].length > decimals ? decimals : parts[1].length);
19 }
20
21 return parts.join(".");
22 }
23 }