mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-26 06:08:40 +01:00
* feat: Introduce `MoneyText` and `CurrencySymbolText` Widgets * feat: add accessibility to `MoneyText`
14 lines
548 B
Dart
14 lines
548 B
Dart
import "dart:math";
|
|
import "package:cw_core/amount/money.dart";
|
|
import "package:cw_core/currency.dart";
|
|
|
|
extension ToMoney on double {
|
|
/// Turn a double representation of a currency amount to a proper Money representation
|
|
/// truncating currencies with more than 20 decimals because double can not handle more
|
|
Money? tryToMoney(Currency currency) =>
|
|
Money.tryParse(toStringAsFixed(min(currency.decimals, 20)), currency);
|
|
|
|
Money toMoney(Currency currency) =>
|
|
Money.parse(toStringAsFixed(min(currency.decimals, 20)), currency);
|
|
}
|