Module money

Module money 

Source
Expand description

Money Module

§Math Functions

This module implements the TMF Money type and provides simple maths functions to make calculations easier.

§Add / Sub Limitations

These maths functions only work for Add and Substract if the currency is the same on both sides of the operator. If there is a difference, the LHS is returned unaltered as these functions cannot fail.

§Mul / Div types

Multiplication and Division has been implemented for both f32 and i32 types. Division by zero is not permitted and will result in the LHS being returned unaltered.

use rust_decimal::Decimal;
use tmflib::common::money::Money;

let unit = Money::from(10.0);
let qty = 5;
let total = unit * qty;
assert_eq!(total.value,Decimal::from(50));

Structs§

Money
Money sub-resource