dev
dart 26 lines 766 Bytes
Raw
1 import 'package:intl/intl.dart';
2 import 'package:cw_core/crypto_amount_format.dart';
3
4 const bitcoinAmountLength = 8;
5 const bitcoinAmountDivider = 100000000;
6 final bitcoinAmountFormat = NumberFormat()
7 ..maximumFractionDigits = bitcoinAmountLength
8 ..minimumFractionDigits = 1;
9
10 String bitcoinAmountToString({required int amount}) =>
11 bitcoinAmountFormat.format(cryptoAmountToDouble(amount: amount, divider: bitcoinAmountDivider));
12
13 double bitcoinAmountToDouble({required int amount}) =>
14 cryptoAmountToDouble(amount: amount, divider: bitcoinAmountDivider);
15
16 int stringDoubleToBitcoinAmount(String amount) {
17 int result = 0;
18
19 try {
20 result = (double.parse(amount) * bitcoinAmountDivider).round();
21 } catch (e) {
22 result = 0;
23 }
24
25 return result;
26 }