mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-26 21:50:27 +00:00
27 lines
749 B
Dart
27 lines
749 B
Dart
|
import 'package:intl/intl.dart';
|
||
|
import 'package:cw_core/crypto_amount_format.dart';
|
||
|
|
||
|
const bitcoinAmountLength = 8;
|
||
|
const bitcoinAmountDivider = 100000000;
|
||
|
final bitcoinAmountFormat = NumberFormat()
|
||
|
..maximumFractionDigits = bitcoinAmountLength
|
||
|
..minimumFractionDigits = 1;
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
return result;
|
||
|
}
|