financial-ops 0.1.0

A Rust library to perform decimal arithmetic without floating point values.
Documentation
  • Coverage
  • 47.62%
    20 out of 42 items documented0 out of 27 items with examples
  • Size
  • Source code size: 28.43 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.49 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Documentation
  • 0xC0A1/financial-ops
    7 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • 0xC0A1

Financial Ops

This crate provides a set of operations for working with financial data, more specifically, avoiding the usage of floating point types.

Usage

use financial_ops::CheckedDecimalOperations;

fn test_add_decimals() {
    let a: u64 = 1_0000;
    let a_decimals = 4;
    let b: u64 = 2_00;
    let b_decimals = 2;

    let (result, decimals) = a.add_decimals_checked(b, a_decimals, b_decimals)?;
    assert_eq!(result, 3_0000);
    assert_eq!(decimals, 4);

    let a: u32 = 123_45;
    let a_decimals = 2;
    let b: u32 = 0_45;
    let b_decimals = 2;

    let (result, decimals) = a.add_decimals_checked(b, a_decimals, b_decimals)?;
    assert_eq!(result, 123_90);
    assert_eq!(decimals, 2);
}

Very useful when dealing with money or blockchain transactions.