Search packages, repositories and app categories

Package detailsv1.0.0

currency_type

Currency type for Dart and Flutter, a large numeric type, with exactly four digit after the decimal point, appropriate for financial calculations.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
84
Likes
27
Pub points
150

Install package

flutter pub add currency_type

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A Dart and Flutter package designed for precise financial calculations, offering a large numeric type that maintains exactly four decimal places. It ensures accuracy in currency operations by preventing floating-point errors common with standard numeric types. Ideal for applications requiring strict monetary precision, such as banking, e-commerce, or accounting systems. The package is platform-agnostic, supporting all major platforms including Android, iOS, Web, macOS, Windows, and Linux.

Use cases

  • Financial transaction processing
  • Currency display in apps
  • Accounting and invoicing systems
  • E-commerce pricing logic
  • Precise monetary arithmetic
  • Budget tracking applications

Key features

  • Fixed four decimal precision
  • Prevents floating-point inaccuracies
  • Supports arithmetic operations
  • Cross-platform compatibility
  • Simple API for currency handling
  • Built-in formatting utilities

Suitable for

  • Developers building financial apps
  • Flutter apps needing accurate money calculations
  • Teams requiring consistent currency representation
  • Applications handling international payments
  • Backend services managing monetary data

Considerations

  • Not suitable for non-monetary large number calculations
  • Requires careful handling of input strings
  • May have performance overhead for very high-frequency operations
  • Limited to four decimal places only
  • Does not support multiple currencies natively

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

currency_type

Version

The Currency type is a large numeric type, with exactly four digit after the decimal point. Internally, Currency using integer calculation to minimizes rounding errors.

The Currency type is appropriate for financial calculations that require large numbers of significant integral, up to four fractional digits, and minimize error caused by floating point calculation.


Why Using Currency ?


Currency prevent rounding error from floating point calculation. Currency also make comparisan more accurate and predictable.


Using Double

func main() {
  var a = 0.7;
  var b = 0.49;
  var c = a * a;

  print('$a * $a = $c');

  if (c == b) {
    print("Equal");
  } else {
    print("Not Equal");
  }
}
0.7 * 0.7 = 0.48999999999999994
Not Equal

Using Currency

func main() {
  var a = Currency.parse('0.7');
  var b = Currency.parse('0.49');
  var c = a * a;

  print('$a * $a = $c');

  if (c == b) {
    print("Equal");
  } else {
    print("Not Equal");
  }
}
0.7000 * 0.7000 = 0.4900
Equal

How To Use


To use currency_type module, you have to add to your project by run following command:

$ dart pub add currency_type 

or add directly in pubspec.yaml

dependencies: 
  currency_type: ^1.0.0

and then import to your dart file

import 'package:currency_type/currency_type.dart';

Variable declaration


You can declare Currency variable in 3 ways:

  1. Create zero value

    var a = Currency();
    
  2. Convert from numbers variable or literal :

    var b = 1234;
    var c = 1234.56;
    
    var d = Currency.from(b);
    var e = Currency.from(c);
    
    var f = Currency.from(1234);
    var g = Currency.from(1234.56);
    
  3. Parsing from string :

    var f = Currency.parse('1234567890');
    var g = Currency.parse('1234567890123456.1234');
    

Operations


You can do arithmetic operation on Currency like addition, subtraction, multiplication, or division.

var h = d + e; 
var i = g - h;
var j = d * e; 
var k = g / f; 

var l = (d + e) * g;

Currency can also be compared to other Currency

if (k == l) {
   ...
}


if (h > Currency.from(100)) {
   ...
}

Big Numbers


Unlike double, Currency can store very big number precisely.

func main() {
  var a = 12345678901234567.1234;
  print("Big Double   : $a");

  var b = Currency.parse('12345678901234567.1234');
  print("Big Currency : $b");
}
Big Double   : 12345678901234568.0
Big Currency : 12345678901234567.1234




Copyright (c) 2021-2025, Mohamad Tantowi Mustofa (tantowi.com)
Licensed under BSD 3-Clause license.

Categories

Source repository

Projects using this package

No data available yet.