#accounting #numbers #money

cents

A small crate for handling monetary values as in integer number of cents

2 releases

0.1.1 Mar 12, 2020
0.1.0 Mar 11, 2020

#356 in Finance

MIT license

6KB
155 lines

cents

A small crate for handling monetary values as in integer number of cents.

Example Usage

use cents::Cents;

// Create a new cents object directly.
let money = Cents::new(21, 21);

// compare it against a cents object created from a u64 value.
assert_eq!(Cents::new(42, 42), 4242.into());


// add it to an u64 value.
assert_eq!(money + 2121, Cents::new(42, 42);

// Add two cents
assert_eq!(Cents::from(2121) + Cents::from(2121), Cents::new(42, 42));

Features

  • Addition (Self, u64)
  • Subtraction (Self)
  • Multiplication (Self, u64)
  • Conversion from BigInt
  • Conversion from u64
  • Equality (Self)

Dependencies

~475KB