currency_formatter 1.2.0 currency_formatter: ^1.2.0 copied to clipboard
A package to easily format money. It supports setting a custom currency symbol and format, using some of the inbuilt ones for the main currencies or using the system one.
import 'package:currency_formatter/currency_formatter.dart';
void main() {
CurrencyFormatter cf = CurrencyFormatter();
CurrencyFormatterSettings euroSettings = CurrencyFormatterSettings(
// formatter settings for euro
symbol: '€',
symbolSide: SymbolSide.left,
thousandSeparator: '.',
decimalSeparator: ',',
);
num amount = 1910.9347;
String formatted = cf.format(amount, euroSettings); // 1.910,93 €
String compact = cf.format(amount, euroSettings, compact: true); // 1,91K €
String threeDecimal =
cf.format(amount, euroSettings, decimal: 3); // 1.910,945 €
String inUSD = cf.format(amount, CurrencyFormatter.usd); // $ 1,910.93
String inRUB = cf.format(amount, cf.majors['rub']!); // 1.910,93 ₽
String jpySymbol = cf.majorSymbols['jpy']!; // ¥
String inSystemCurrency =
cf.format(amount, cf.getLocal() ?? cf.majors['usd']!);
String fromSymbol = cf.format(amount, cf.getFromSymbol('£')!); // £ 1,910.35
}