money 0.1.6

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 76

Money

Dart implementation of Fowler's Money pattern.

Pub version License documentation codecov Build Status

Stories in Ready

Usage Examples

Creating a Money object and accessing its monetary value

// Create a money object that represents 1 USD
var money = new Money(100, new Currency('USD'));

// Access the Money object's monetary value
print(money.amount); // => 100

// -- OR --
print(money.amountAsString); // => 1.00

Creating a Money object from a string value

var money = new Money.fromString('12.50', new Currency('USD'));

print(money.amount); // => 1250

Creating a money from a double value

var money = new Money.fromDouble(12.34, new Currency('USD'));

print(money.amount); // => 1234

Simple conversion to a string

var money = new Money(150, new Currency('USD'));

print(money.toString()); // => 1.50 USD

Basic arithmetic using Money objects

// Create two Money objects that represent 1 USD and 2 USD, respectively
final a = new Money(100, new Currency('USD'));
final b = new Money(200, new Currency('USD'));

var c = null;

// Negate a Money object
c = -a;
print(c); // => -1.00 USD

// Calculate the sum of two Money objects
c = a + b;
print(c); // => 3.00 USD


// Calculate the difference of two Money objects
c = b - a;
print(c); // => 1.00 USD

// Multiply a Money object with a factor
c = a * 2;
print(c); // => 2.00 USD

Comparing Money objects

final a = new Money(100, new Currency('USD'));
final b = new Money(200, new Currency('USD'));

a < b; // => true
a > b; // => false

b <= a; // => false
b => a; // => true

a.compareTo(b); // => -1
a.compareTo(a); // =>  0
b.compareTo(a); // =>  1

The compareTo() method returns an integer less than, equal to, or greater than zero if the value of one Money object is considered to be respectively less than, equal to, or greater than that of another Money object.

Money implements Comparable interface and you can sort a list of Money objects.

Allocate the monetary value represented by a Money object using a list of ratios

final a = new Money(5, new Currency('USD'));

for (var c in a.allocate(3, 7)) {
  print(c);
}

The code above produces the output shown below:

2
3

Change Log

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

0.1.6 - 2017-02-24

Fixed

  • Fixed wrong parsing from string when integer part of amount is 0.

0.1.5 - 2016-07-06

Changed

  • Class Currency is not abstract from now on.

Fixed

  • Money.hashCode now relates on amount and currency (Issue #1).

0.1.4 - 2016-06-03

Changed

  • [BC] Money.==() now receives Object instead of Money and checks runtime type of the argument, closes #4.

0.1.3+2 - 2016-05-10

Fixed

  • Fixed invalid rounding of amount in Money.toString(), closes #3.

0.1.3 - 2015-05-05

Added

  • Added Money.fromDouble() constructor.

0.1.2 - 2015-05-05

Added

  • Added getter Money.amountAsString.

0.1.1 - 2015-05-04

Added

  • Added Money.fromString() constructor.
  • Added relational operators (<, <=, >, >=).

0.1.0+1 - 2015-05-01

Fixed

  • Fixes README.md.

[0.1.0] - 2015-05-01

Initial version.

1. Depend on it

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


dependencies:
  money: "^0.1.6"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:money/money.dart';
        
Version Uploaded Documentation Archive
0.1.6 Feb 24, 2017 Go to the documentation of money 0.1.6 Download money 0.1.6 archive
0.1.5 Jul 5, 2016 Go to the documentation of money 0.1.5 Download money 0.1.5 archive
0.1.4 Jun 3, 2016 Go to the documentation of money 0.1.4 Download money 0.1.4 archive
0.1.3+2 May 10, 2016 Go to the documentation of money 0.1.3+2 Download money 0.1.3+2 archive
0.1.3+1 May 6, 2015 Go to the documentation of money 0.1.3+1 Download money 0.1.3+1 archive
0.1.3 May 5, 2015 Go to the documentation of money 0.1.3 Download money 0.1.3 archive
0.1.2 May 5, 2015 Go to the documentation of money 0.1.2 Download money 0.1.2 archive
0.1.1 May 4, 2015 Go to the documentation of money 0.1.1 Download money 0.1.1 archive
0.1.0+1 May 1, 2015 Go to the documentation of money 0.1.0+1 Download money 0.1.0+1 archive
0.1.0 May 1, 2015 Go to the documentation of money 0.1.0 Download money 0.1.0 archive

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
51 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
76

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:money/money.dart.

Suggestions

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use money.dart.

  • Use analysis_options.yaml.

    Rename old .analysis_options file to analysis_options.yaml.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <2.0.0
Dev dependencies
coverage any
dart_dev any
dart_style any
test >=0.12.14 <0.13.0