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

패키지 상세v0.0.7

money_formatter

MoneyFormatter는 로컬라이제이션에 종속되지 않고, 원하는 특성에 따라 다양한 통화 형식을 지정할 수 있는 Flutter 확장입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
3.6천
좋아요
88
Pub 점수
135

패키지 설치

flutter pub add money_formatter

패키지 개요

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

MoneyFormatter는 여러 플랫폼에서 유연하고 사용자 정의 가능한 통화 형식을 가능하게 하는 Flutter 패키지입니다. 로컬라이제이션에 의존하지 않고 다양한 통화 기호, 소수점 자릿수, 구분 기호 및 접두사/접미사를 지원하여 숫자를 돈으로 포맷할 수 있습니다. 동적 또는 비표준적인 금액 표시가 필요한 앱에 적합하며, 외관에 대한 정밀한 제어를 제공하면서 성능과 크로스플랫폼 일관성을 유지합니다.

사용 사례

  • 전자상거래 가격 표시
  • 금융 앱 거래 형식
  • 사용자 지정 통화 기호 처리
  • 다중 지역 앱에서의 동적 가격 설정
  • 마스크를 사용한 사용자 입력 형식 지정
  • 실시간 환율 변환 미리보기

주요 기능

  • 사용자 정의 통화 기호
  • 사용자 정의 소수 자릿수 및 구분 기호
  • 접두사 및 접미사 지원
  • 로컬라이제이션에 대한 종속성 없음
  • 크로스 플랫폼 호환성
  • 텍스트 필드와의 간편한 통합

적합한 대상

  • 유연한 통화 형식이 필요한 개발자
  • 표준이 아닌 통화 형식을 가진 앱
  • 다중 지역 금융 애플리케이션
  • 실시간 숫자 형식 지정이 필요한 UI 구성 요소
  • 내장된 로컬라이제이션 제약을 피하는 프로젝트

고려 사항

  • 기본적으로 지역별 형식 지정을 처리하지 않습니다
  • 각 통화에 대해 수동 구성이 필요합니다
  • 사용자 입력에 대한 추가 검증이 필요할 수 있습니다
  • 고주기 업데이트에 최적화되지 않음
  • 기본 설정을 초과한 내장 통화 목록이 제한되어 있음

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

money_formatter

MoneyFormatter is a Flutter package to formatting various types of currencies according to the characteristics you like, without having to be tied to any localization.

latest version last commit

Dependencies :

intl

Screenshot

screenshot


Install

For complete steps in installing MoneyFormatter you can see in the Installation Guide.

Usage

Import the library

import 'package:flutter_money_formatter/flutter_money_formatter.dart';

Getting Started

To be able to format your double value into the various formats you want, you first need to create a MoneyFormatter instance like the following:

MoneyFormatter fmf = MoneyFormatter(
    amount: 12345678.9012345
);

Note, the code above still uses the default configuration as explained here.

After that, you can request various results of the format as follows:

// normal form
print(fmf.output.nonSymbol); // 12,345,678.90
print(fmf.output.symbolOnLeft); // $ 12,345,678.90
print(fmf.output.symbolOnRight); // 12,345,678.90 $
print(fmf.output.fractionDigitsOnly); // 90
print(fmf.output.withoutFractionDigits); // 12,345,678

// compact form
print(fmf.output.compactNonSymbol) // 12.3M
print(fmf.output.compactSymbolOnLeft) // $ 12.3M
print(fmf.output.compactSymbolOnRight) // 12.3M $

If you will use the output format several times, I strongly recommend that you initialize a variable as in the following example:

MoneyFormatterOutput fo = fmf.output;

Or directly when initializing the MoneyFormatter instance as in the following example:

MoneyFormatterOutput fo = MoneyFormatter(
    amount: 12345678.9012345
).output;

So you can immediately take the value more easily as in the following example:

// normal form
print(fo.nonSymbol); // 12,345,678.90
print(fo.symbolOnLeft); // $ 12,345,678.90
print(fo.symbolOnRight); // 12,345,678.90 $
print(fo.fractionDigitsOnly); // 90
print(fo.withoutFractionDigits); // 12,345,678

// compact form
print(fo.compactNonSymbol) // 12.3M
print(fo.compactLeftSymbol) // $ 12.3M
print(fo.compactRightSymbol) // 12.3M $

See demo section to get more info.

Configurations

To adjust the format to suit your needs, you can set it through the settings parameter:

MoneyFormatter fmf = new MoneyFormatter(
    amount: 12345678.9012345,
    settings: MoneyFormatterSettings(
        symbol: 'IDR',
        thousandSeparator: '.',
        decimalSeparator: ',',
        symbolAndNumberSeparator: ' ',
        fractionDigits: 3,
        compactFormatType: CompactFormatType.sort
    )
)

Of course you are not required to initialize the entire configuration in the settings (MoneyFormatterSettings) parameter as in the example above. You can change one or more of the configurations above. This is because each configuration above is not mandatory and has a default value.


Properties, Methods, and Functions

  • MoneyFormatter

Property Names Data Type Descriptions
amount double Amount number that will be formatted.
settings MoneyFormatterSettings See here.
output MoneyFormatterOutput See here.
comparator MoneyFormatterCompare See here.
copyWith MoneyFormatter see here
fastCalc MoneyFormatter see here
  • MoneyFormatterSettings

Configuration Property Data Type Default Value Description
symbol String $ (Dollar Sign) The symbol that will be used on formatted output.
thousandSeparator String , The character that will be used as thousand separator on formatted output.
decimalSeparator String . The character that will be used as decimal separator on formatted output.
fractionDigits int 2 The fraction digits that will be used on formatted output.
symbolAndNumberSeparator String ' ' (Space) The character that will be used as separator between formatted number and currency symbol.
compactFormatType CompactFormatType CompactFormatType.short See here.
  • CompactFormatType

You can change the type of compact format like for million using M or million, or trillion using T or trillion. and so on. This type only supports two type as described below:

Value Description
CompactFormatType.short Used to make the compact format displayed using short text.
CompactFormatType.long Used to make the compact format displayed using long text.
  • MoneyFormatterOutput

You can use formats that match your needs through properties found in the MoneyFormatterOutput instance.

Property Names Data Type Descriptions
nonSymbol String The results of the format of the currency are normal and without a currency symbol. Example: 12,345,678.90
symbolOnLeft String The results of the normal currency format and with currency symbols are on the left. Example: $ 12,345,678.90
symbolOnRight String The results of the normal currency format and with currency symbols are on the right. Example: 12,345,678.90 $
compactNonSymbol String The results of the currency format are compact and without a currency symbol. Example: 12.3M
compactSymbolOnLeft String The results of the currency format are compact and with currency symbols on the left. example: $ 12.3M
compactSymbolOnRight String The results of the currency format are compact and with currency symbols on the right. example: 12.3M $
fractionDigitsOnly String Only give the fraction value. Example: 90
withoutFractionDigits String Give a value without fractions. Example: 12,345,678
  • MoneyFormatterCompare

Method Parameter Descriptions
isLowerThan amount Check current instance-amount is lower than [amount] or not.
isGreaterThan amount Check current instance-amount is greater than [amount] or not.
isEqual amount Check current instance amount is equal than [amount] or not.
isEqualOrLowerThan amount Check current instance amount is equal or lower than [amount] or not.
isEqualOrGreaterThan amount Check current instance amount is equal or greater than [amount] or not.

Example of using a comparator:

MoneyFormatter fmf = MoneyFormatter(amount: 12345678.9012345);
double comparerValue = 5678.9012;

print(fmf.comparator.isEqual(comparerValue)); // false
print(fmf.comparator.isGreaterThan(comparerValue)); // true


FastCalc

fastCalc is a function that can be used to perform various fast calculation processes that you might need. In implementing it, the fastCalc function gives the output of a MoneyFormatter instance so you can perform several calculation functions at once with the chaining method.

Function:

MoneyFormatter fastCalc({
    @required FastCalcType type, 
    @required double amount
})

Implementation:

MoneyFormatter fmf = MoneyFormatter(amount: 12345.678);
fmf.fastCalc(type: FastCalcType.addition, amount: 1.111);
fmf.fastCalc(type: FastCalcType.substraction, amount: 2.222);

print(fmf.output.nonSymbol); // 12,345.68

Because it supports the chaining process, the example above can be shortened as follows:

MoneyFormatter fmf = MoneyFormatter(amount: 12345.678)
    .fastCalc(type: FastCalcType.addition, amount: 1.111)
    .fastCalc(type: FastCalcType.substraction, amount: 2.222);

print(fmf.output.nonSymbol);  // 12,345.68

The type parameter used by the fastCalc function has the FastCalcType data type which is an enum. The following table is an explanation for the FastCalcType enum:

Index Name Description
0 addition Used to do addition calculations.
1 substraction Used to do substraction calculations.
2 multiplication Used to do multiplication calculations.
3 division Used to do division calculations.
4 percentageAddition Used to do the addition calculations base on percentage.
5 percentageSubstraction Used to do the substraction calculations base on percentage.

Duplicating Instance

For some reasons, you may need to duplicate the instance and just need to change some configurations. To do that, you can use the copyWith method as below:

MoneyFormatter fmf = MoneyFormatter(amount: 12345678.9012345);

print(fmf.output.symbolOnLeft); // $ 12,345,678.90
print(fmf.copyWith(symbol: 'IDR', symbolAndNumberSeparator: '-').output.symbolOnLeft); // IDR-12,345,678.90

Demo

For more complete samples, you can grab it from the example directory.

Help Me

If you find some issues or bugs, please report here. You can also help in requesting new features here.

ChangeLog

Are you curious about the changes that occur in each version? See here for detailed informations.

Contributors

Name Links
Fadhly Permata https://github.com/wiseminds
Gerrel https://github.com/Gerrel
Wisdom Ekeh https://github.com/wiseminds

카테고리

의존성

의존성 목록 1 개

소스 저장소

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

아직 데이터가 없습니다.