Pakete, Repositories und App-Kategorien suchen

Paketdetailsv2.3.0

currency_formatter

Ein Paket zur einfachen Formatierung von Geldbeträgen. Es unterstützt die Einstellung eines benutzerdefinierten Währungssymbols und -formats, entweder durch Verwendung einiger integrierter Formate für die wichtigsten Währungen oder durch Verwendung des Systems.

AndroidiOSWebmacOSWindowsLinux
30-Tage-Downloads
13.500
Likes
50
Pub-Punkte
150

Paket installieren

flutter pub add currency_formatter

Paketübersicht

Aus öffentlichen Paketdaten erstellte Orientierung.

Ein Flutter-Paket, das die Formatierung von Geldbeträgen vereinfacht. Es ermöglicht Benutzern, Zahlen als Währung mit Unterstützung für benutzerdefinierte Symbole, vordefinierte Formate für wichtige Währungen oder systemeigene Währungseinstellungen zu formatieren. Ideal für Anwendungen, die eine konsistente und lokalisierte Darstellung von Geldbeträgen erfordern, wie E-Commerce-, Finanz-Apps oder Ausgabenverfolger. Das Paket ist leichtgewichtig und kompatibel mit allen wichtigen Plattformen, um eine einheitliche Benutzererfahrung sicherzustellen.

Anwendungsfälle

  • Preise in E-Commerce-Apps anzeigen
  • Ausgaben in Budgetierungs-Tools formatieren
  • Währung in internationalen Apps lokalisieren
  • Transaktionsbeträge in Finanzdashboards anzeigen
  • Anpassen von Währungssymbolen in Multi-Region-Apps

Hauptmerkmale

  • Unterstützt benutzerdefinierte Währungssymbole
  • Enthält integrierte Formate für wichtige Währungen
  • Verwendet standardmäßig systemdefinierte Währung
  • Plattformübergreifende Kompatibilität
  • Einfache API zur Formatierung von Zahlen
  • Konfigurierbare Dezimal- und Tausendertrennzeichen

Geeignet für

  • Entwickler, die Finanz- oder Einkaufs-Apps erstellen
  • Apps, die mehrere Regionen ansprechen
  • Projekte, die eine lokalisierte Währungsanzeige benötigen
  • Teams, die eine minimale Einrichtung für die Währungsformatierung wünschen
  • Benutzer, die eine native wie Währungsdarstellung bevorzugen

Hinweise

  • Erfordert manuelle Handhabung der Währungscode-Zuordnung
  • Beschränkt auf Formatierung; analysiert oder überprüft die Eingabe nicht
  • Möglicherweise ist zusätzliche Logik für die bidirektionale Währungsumrechnung erforderlich
  • Hängt von den Lokalisierungseinstellungen für die Systemwährungsrückfall ab
  • Nicht für Echtzeit-Währungskursaktualisierungen optimiert

Original-README

Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.

currency_formatter

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.

Format money

To set how a double will be formatted, create a CurrencyFormat:

CurrencyFormat euroSettings = CurrencyFormat(
  code: 'eur',
  symbol: '€',
  symbolSide: SymbolSide.left,
  thousandSeparator: '.',
  decimalSeparator: ',',
  symbolSeparator: ' ',
);
  • symbolSide can be set to SymbolSide.left, SymbolSide.right, or SymbolSide.none.
  • thousandSeparator and decimalSeparator default to '.', ',' or ',','.' automatically depending on symbolSide.
  • negativeSignPlacement can be set to NegativeSignPlacement.beforeSymbol or NegativeSignPlacement.afterSymbol, and defaults to NegativeSignPlacement.afterSymbol.

To format a num, CurrencyFormatter.format() is used:

num amount = 1910.9347;
String formatted = CurrencyFormatter.format(amount, euroSettings); // 1.910,93 €
String compact = CurrencyFormatter.format(amount, euroSettings, compact: true); // 1,91K €
String threeDecimal = CurrencyFormatter.format(amount, euroSettings, decimal: 3); // 1.910,945 €

Parse formatted money

To get a num from a formatted String, use CurrencyFormatter.parse():

// Above's example continuation
num parseFormatted = CurrencyFormatter.parse(formatted, euroSettings); // 1910.93
num parseCompact = CurrencyFormatter.parse(compact, euroSettings); // 1910.0
num parseThreeDecimal = CurrencyFormatter.parse(threeDecimal, euroSettings); // 1910.935

Predefined CurrencyFormats

Predefined settings for many currencies are also included in this package. They are listed in the CurrencyFormatter.majorsList list and defined as static constants in the CurrencyFormat class.

String inUSD = CurrencyFormatter.format(amount, CurrencyFormat.usd); // $ 1,910.93
String inRUB = CurrencyFormatter.format(amount, CurrencyFormatter.fromCode('rub')!); // 1.910,93 ₽

String jpySymbol = CurrencyFormatter.jpy.symbol; // ¥
Get local CurrencyFormat

In Flutter, you can get the default CurrencyFormat according to the device language using CurrencyFormat.local:

String inSystemCurrency = CurrencyFormatter.format(amount, CurrencyFormat.local ?? CurrencyFormat.usd);

If instead you want to get the CurrencyFormat for a specific locale, use CurrencyFormat.fromLocale():

String inLocaleCurrency = CurrencyFormatter.format(amount, CurrencyFormat.fromLocale('en_US')!);
Get CurrencyFormat from symbol or code

You can get a CurrencyFormat from a currency symbol (if it is in CurrencyFormatter.majors) with CurrencyFormat.fromSymbol():

String fromSymbol = CurrencyFormatter.format(amount, CurrencyFormat.fromSymbol('£')!); // £ 1,910.35

String fromCode = CurrencyFormatter.format(amount, CurrencyFormat.fromCode('gbp')!); // £ 1,910.35

Using custom currencies

Let's say you want to use the following custom currency seamlessly:

CurrencyFormat khr = CurrencyFormat(
  symbol: '៛',
  symbolSide: SymbolSide.right,
);

You can create your own majors list:

const List<CurrencyFormat> myCurrencies = [
  ...CurrencyFormatter.majorsList,
  khr,
];

And use it to get the currency corresponding to a symbol or code, or the local one:

CurrencyFormat.fromSymbol('៛', myCurrencies); // khr
CurrencyFormat.fromCode('khr', myCurrencies); // khr

// custom local currency
CurrencyFormat? localCurrency() =>
    CurrencyFormat.fromSymbol(CurrencyFormat.localSymbol, myCurrencies);
// or
CurrencyFormat? localCurrency() =>
    CurrencyFormat.fromLocale(null, myCurrencies);

Kategorien

Abhängigkeiten

Abhängigkeiten 2 Einträge

  • intl>=0.17.0 <0.21.0
  • web>=1.0.0 <=3.0.0

Quell-Repository

Projekte, die dieses Paket verwenden

Noch keine Daten verfügbar.