패키지, 저장소 및 앱 카테고리 검색

패키지 상세v2.3.0

currency_formatter

금액을 쉽게 형식화할 수 있는 패키지입니다. 사용자 정의 통화 기호와 형식을 설정할 수 있으며, 주요 통화용 내장 형식 중 일부를 사용하거나 시스템 형식을 사용할 수 있습니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
1.4만
좋아요
50
Pub 점수
150

패키지 설치

flutter pub add currency_formatter

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

금액 값을 포맷하는 것을 간소화하는 플러터 패키지입니다. 사용자가 사용자 정의 기호, 주요 통화에 대한 사전 정의된 형식 또는 시스템 기본 통화 설정을 사용하여 숫자를 통화로 포맷할 수 있습니다. 전자상거래, 금융 앱 또는 지출 추적기와 같은 일관되고 지역화된 금액 표시가 필요한 애플리케이션에 적합합니다. 이 패키지는 가볍고 모든 주요 플랫폼과 호환되어 일관된 사용자 경험을 보장합니다.

사용 사례

  • 전자상거래 앱에서 가격 표시
  • 예산 도구에서 비용 형식 지정
  • 국제 앱에서 통화 로컬라이징
  • 재무 대시보드에서 거래 금액 표시
  • 다중 지역 앱에서 통화 기호 맞춤 설정

주요 기능

  • 사용자 정의 통화 기호 지원
  • 주요 통화에 대한 내장 형식을 포함
  • 기본적으로 시스템에서 정의한 통화를 사용합니다
  • 크로스 플랫폼 호환성
  • 숫자 형식 지정을 위한 간단한 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

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.