パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v2.3.0

currency_formatter

お金のフォーマットを簡単にできるパッケージです。カスタム通貨シンボルやフォーマットを設定でき、主要通貨の組み込みフォーマットの一部を使用するか、システムのものを使うことができます。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
1.4万
いいね数
50
Pub ポイント
150

パッケージをインストール

flutter pub add currency_formatter

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

通貨価値のフォーマットを簡素化するFlutterパッケージです。カスタムシンボル、主要通貨用の事前定義フォーマット、またはシステムデフォルトの通貨設定に対応して、数値を通貨としてフォーマットできます。ECサイト、金融アプリ、経費トラッカーなど、一貫性がありローカライズされた金額表示が必要なアプリに最適です。軽量で、すべての主要プラットフォームと互換性があり、均一なユーザー体験を提供します。

用途

  • eコマースアプリでの価格表示
  • 予算ツールでの経費のフォーマット
  • 国際アプリにおける通貨のローカライズ
  • 財務ダッシュボードでの取引金額の表示
  • マルチリージョンアプリでの通貨記号のカスタマイズ

主な機能

  • カスタム通貨記号をサポート
  • 主要な通貨用の組み込み形式を含む
  • デフォルトではシステム定義の通貨を使用します
  • クロスプラットフォーム互換性
  • 数値のフォーマット用のシンプルな API
  • 小数および千単位の区切り記号をカスタマイズ可能

適している対象

  • 金融またはショッピングアプリを開発する開発者
  • 複数の地域をターゲットにするアプリ
  • ローカライズされた通貨表示が必要なプロジェクト
  • 通貨形式の設定を最小限に抑えたいチーム
  • ネイティブな通貨表示を好むユーザー

注意事項

  • 通貨コードマッピングの手動処理が必要です
  • フォーマットに限定され、入力を解析または検証しない
  • 双方向通貨変換のための追加ロジックが必要になる可能性があります
  • システム通貨のフォールバックのロケール設定に依存します
  • リアルタイム為替レートの更新には最適化されていません

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

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);

カテゴリー

依存関係

依存関係一覧 2 件

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

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。