flutter_money_formatter 0.8.2

FlutterMoneyFormatter #

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

latest version last commit License

Dependencies : #

intl

Screenshot #

screenshot


Install #

For complete steps in installing FlutterMoneyFormatter 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 FlutterMoneyFormatter instance like the following:

FlutterMoneyFormatter fmf = FlutterMoneyFormatter(
    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 FlutterMoneyFormatter instance as in the following example:

MoneyFormatterOutput fo = FlutterMoneyFormatter(
    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:

FlutterMoneyFormatter fmf = new FlutterMoneyFormatter(
    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 #

  • FlutterMoneyFormatter #

Property NamesData TypeDescriptions
amountdoubleAmount number that will be formatted.
settingsMoneyFormatterSettingsSee here.
outputMoneyFormatterOutputSee here.
comparatorMoneyFormatterCompareSee here.
copyWithFlutterMoneyFormattersee here
fastCalcFlutterMoneyFormattersee here
  • MoneyFormatterSettings #

Configuration PropertyData TypeDefault ValueDescription
symbolString$ (Dollar Sign)The symbol that will be used on formatted output.
thousandSeparatorString,The character that will be used as thousand separator on formatted output.
decimalSeparatorString.The character that will be used as decimal separator on formatted output.
fractionDigitsint2The fraction digits that will be used on formatted output.
symbolAndNumberSeparatorString' ' (Space)The character that will be used as separator between formatted number and currency symbol.
compactFormatTypeCompactFormatTypeCompactFormatType.shortSee 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:

ValueDescription
CompactFormatType.shortUsed to make the compact format displayed using short text.
CompactFormatType.longUsed 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 NamesData TypeDescriptions
nonSymbolStringThe results of the format of the currency are normal and without a currency symbol. Example: 12,345,678.90
symbolOnLeftStringThe results of the normal currency format and with currency symbols are on the left. Example: $ 12,345,678.90
symbolOnRightStringThe results of the normal currency format and with currency symbols are on the right. Example: 12,345,678.90 $
compactNonSymbolStringThe results of the currency format are compact and without a currency symbol. Example: 12.3M
compactSymbolOnLeftStringThe results of the currency format are compact and with currency symbols on the left. example: $ 12.3M
compactSymbolOnRightStringThe results of the currency format are compact and with currency symbols on the right. example: 12.3M $
fractionDigitsOnlyStringOnly give the fraction value. Example: 90
withoutFractionDigitsStringGive a value without fractions. Example: 12,345,678
  • MoneyFormatterCompare #

MethodParameterDescriptions
isLowerThanamountCheck current instance-amount is lower than [amount] or not.
isGreaterThanamountCheck current instance-amount is greater than [amount] or not.
isEqualamountCheck current instance amount is equal than [amount] or not.
isEqualOrLowerThanamountCheck current instance amount is equal or lower than [amount] or not.
isEqualOrGreaterThanamountCheck current instance amount is equal or greater than [amount] or not.

Example of using a comparator:

FlutterMoneyFormatter fmf = FlutterMoneyFormatter(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 aFlutterMoneyFormatter instance so you can perform several calculation functions at once with the chaining method.

Function:

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

Implementation:

FlutterMoneyFormatter fmf = FlutterMoneyFormatter(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:

FlutterMoneyFormatter fmf = FlutterMoneyFormatter(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:

IndexNameDescription
0additionUsed to do addition calculations.
1substractionUsed to do substraction calculations.
2multiplicationUsed to do multiplication calculations.
3divisionUsed to do division calculations.
4percentageAdditionUsed to do the addition calculations base on percentage.
5percentageSubstractionUsed 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:

FlutterMoneyFormatter fmf = FlutterMoneyFormatter(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.

Our Other Package #

See our other packages here.

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.

LICENSE #

Copyright (c) 2019, Fadhly Permata <fadhly.permata@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the 'FlutterMoneyFormatter' project.

Version 0.8.* #

  • [0.8.2]

    • [UPDATES]
      • Upgrade Intl version
  • [0.8.1]

  • [0.8.0]

    • [ADD]

      • fastCalc method
    • [UPDATES]

      • fix miss-type on CompactFormatType.sort
      • Update documentations

Version 0.7.* #

  • [0.7.3]

  • [0.7.2]

    • [FIX]

    • [ADD]

      • Screenshot on documentation
  • [0.7.1]

  • [0.7.0]

    • [FIX]

      • fractionDigitsOnly bugs when using custom decimal symbol.
      • withoutFractionDigits bugs when using custom decimal symbol.
      • Fix typo on documentation
    • [ADD]

      • Add license info on documentation

Version 0.6.* #

  • [0.6.3]

  • [0.6.2]

    • [UPDATE]
      • License badge on documentation.
  • [0.6.1]

  • [0.6.0]

    Be careful, this version has a lot of changes. After updating this version makes your application need to be revised as well.

    • [CHANGES]
      • Classified settings, output, and comparator, see documentation for more information.
      • Update documentation to match with current version.
      • Changing the license from the MIT license becomes a BSD license.
      • License notes on each file.
      • Code improvements.

Version 0.5.* #

  • [0.5.4]

    • [DEPRECATED] spaceBetweenSymbolAndNumber is deprecated and updated with symbolAndNumberSeparator
    • [ADD] symbolAndNumberSeparator with String data type.
    • [UPDATE] documentation to match with the library capability.
    • [UPDATE] Formatting source code as suggested by pub.dartlang.org.
  • [0.5.3]

    • [FIX] UPDATELOG format
  • [0.5.2]

    • [FIX] Fix missing tags on documentation
    • [ADD] License notice on library
    • [ADD] library tag on header
  • [0.5.1]

    • [UPDATE] Update documentation
  • [0.5.0]

    • [FIX] Compact form as described here
    • [DEPRECATED] CompactFormatCase.
    • [UPDATE] Update documentation.
    • [ADD] CompactFormatType enum on format settings

Version 0.4.* #

  • [0.4.8+1]

  • [0.4.8]

  • [0.4.7]

    • [UPDATE] Package description
    • [UPDATE] Enhance documentation
  • [0.4.6]

    • [FIX] Inconsisten naming on source code & documentation
  • [0.4.5]

    • [FIX] Documentation for method name changes.
  • [0.4.2]

    • [UPDATE] Revise license note.
  • [0.4.1]

    • [ADD] Compact format support
    • [ADD] Version badges on documentation
  • [0.4.0]

    • [ADD] Compact format support.
    • [UPDATE] Update documentation.

Version 0.3.* #

  • [0.3.1]

    • [ADD] Some badges on documentation
  • [0.3.0]

    • [UPDATE] Documentation
    • [ADD] Compare methods:
      • isLowerThan
      • isGreaterThan
      • isEqual
      • isEqualOrLowerThan
      • isEqualOrGreaterThan

Version 0.2.* #

  • [0.2.2]

    • [ADD] Document public APIs
  • [0.2.1]

    • [FIX] Someline on documention files.
  • [0.2.0]

    • [OPTIMIZE] UPDATE meta package into foundation package.

Version 0.1.* #

  • [0.1.1]

    • [ADD] Documentation
    • [OPTIMIZE] Removing unecessary line
  • [0.1.0]

    • Initial Release

example/README.md

FlutterMoneyFormatter #

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

latest version last commit License

Dependencies : #

intl

Screenshot #

screenshot


Install #

For complete steps in installing FlutterMoneyFormatter 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 FlutterMoneyFormatter instance like the following:

FlutterMoneyFormatter fmf = FlutterMoneyFormatter(
    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 FlutterMoneyFormatter instance as in the following example:

MoneyFormatterOutput fo = FlutterMoneyFormatter(
    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:

FlutterMoneyFormatter fmf = new FlutterMoneyFormatter(
    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 #

  • FlutterMoneyFormatter #

Property NamesData TypeDescriptions
amountdoubleAmount number that will be formatted.
settingsMoneyFormatterSettingsSee here.
outputMoneyFormatterOutputSee here.
comparatorMoneyFormatterCompareSee here.
copyWithFlutterMoneyFormattersee here
fastCalcFlutterMoneyFormattersee here
  • MoneyFormatterSettings #

Configuration PropertyData TypeDefault ValueDescription
symbolString$ (Dollar Sign)The symbol that will be used on formatted output.
thousandSeparatorString,The character that will be used as thousand separator on formatted output.
decimalSeparatorString.The character that will be used as decimal separator on formatted output.
fractionDigitsint2The fraction digits that will be used on formatted output.
symbolAndNumberSeparatorString' ' (Space)The character that will be used as separator between formatted number and currency symbol.
compactFormatTypeCompactFormatTypeCompactFormatType.shortSee 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:

ValueDescription
CompactFormatType.shortUsed to make the compact format displayed using short text.
CompactFormatType.longUsed 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 NamesData TypeDescriptions
nonSymbolStringThe results of the format of the currency are normal and without a currency symbol. Example: 12,345,678.90
symbolOnLeftStringThe results of the normal currency format and with currency symbols are on the left. Example: $ 12,345,678.90
symbolOnRightStringThe results of the normal currency format and with currency symbols are on the right. Example: 12,345,678.90 $
compactNonSymbolStringThe results of the currency format are compact and without a currency symbol. Example: 12.3M
compactSymbolOnLeftStringThe results of the currency format are compact and with currency symbols on the left. example: $ 12.3M
compactSymbolOnRightStringThe results of the currency format are compact and with currency symbols on the right. example: 12.3M $
fractionDigitsOnlyStringOnly give the fraction value. Example: 90
withoutFractionDigitsStringGive a value without fractions. Example: 12,345,678
  • MoneyFormatterCompare #

MethodParameterDescriptions
isLowerThanamountCheck current instance-amount is lower than [amount] or not.
isGreaterThanamountCheck current instance-amount is greater than [amount] or not.
isEqualamountCheck current instance amount is equal than [amount] or not.
isEqualOrLowerThanamountCheck current instance amount is equal or lower than [amount] or not.
isEqualOrGreaterThanamountCheck current instance amount is equal or greater than [amount] or not.

Example of using a comparator:

FlutterMoneyFormatter fmf = FlutterMoneyFormatter(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 aFlutterMoneyFormatter instance so you can perform several calculation functions at once with the chaining method.

Function:

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

Implementation:

FlutterMoneyFormatter fmf = FlutterMoneyFormatter(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:

FlutterMoneyFormatter fmf = FlutterMoneyFormatter(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:

IndexNameDescription
0additionUsed to do addition calculations.
1substractionUsed to do substraction calculations.
2multiplicationUsed to do multiplication calculations.
3divisionUsed to do division calculations.
4percentageAdditionUsed to do the addition calculations base on percentage.
5percentageSubstractionUsed 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:

FlutterMoneyFormatter fmf = FlutterMoneyFormatter(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.

Our Other Package #

See our other packages here.

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.

LICENSE #

Copyright (c) 2019, Fadhly Permata <fadhly.permata@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the 'FlutterMoneyFormatter' project.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_money_formatter: ^0.8.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_money_formatter/flutter_money_formatter.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
92
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
96
Learn more about scoring.

We analyzed this package on Jul 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
intl ^0.15.8 0.15.8
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
path 1.6.2
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8

Admin