You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cake_wallet/lib/bitcoin/bitcoin_amount_format.dart

29 lines
783 B

3 years ago
import 'dart:math';
4 years ago
import 'package:intl/intl.dart';
4 years ago
import 'package:cake_wallet/entities/crypto_amount_format.dart';
4 years ago
const bitcoinAmountLength = 8;
const bitcoinAmountDivider = 100000000;
final bitcoinAmountFormat = NumberFormat()
..maximumFractionDigits = bitcoinAmountLength
..minimumFractionDigits = 1;
3 years ago
String bitcoinAmountToString({int amount}) => bitcoinAmountFormat.format(
cryptoAmountToDouble(amount: amount, divider: bitcoinAmountDivider));
double bitcoinAmountToDouble({int amount}) =>
cryptoAmountToDouble(amount: amount, divider: bitcoinAmountDivider);
int stringDoubleToBitcoinAmount(String amount) {
int result = 0;
try {
result = (double.parse(amount) * bitcoinAmountDivider).toInt();
} catch (e) {
result = 0;
3 years ago
}
4 years ago
3 years ago
return result;
}