diff options
| author | Kevin Hoerr <kjhoerr@submelon.dev> | 2026-04-21 18:17:31 -0400 |
|---|---|---|
| committer | Kevin Hoerr <kjhoerr@submelon.dev> | 2026-04-21 18:17:31 -0400 |
| commit | bdd5748b41a6e85c1e8a3cd991c55c0890e39e24 (patch) | |
| tree | 9bedd9f561e762caf64611867cf9378b1a961d4b | |
| parent | b063236e8d548b1c28e9cfd51c1fc0d470a46de5 (diff) | |
| download | equity-tracker-bdd5748b41a6e85c1e8a3cd991c55c0890e39e24.tar.gz equity-tracker-bdd5748b41a6e85c1e8a3cd991c55c0890e39e24.tar.bz2 equity-tracker-bdd5748b41a6e85c1e8a3cd991c55c0890e39e24.zip | |
records.rs: Remove unnecessary use of bigdecimal Context
| -rw-r--r-- | src/app/store/records.rs | 15 |
1 files changed, 3 insertions, 12 deletions
diff --git a/src/app/store/records.rs b/src/app/store/records.rs index fd7fec6..4e85fc1 100644 --- a/src/app/store/records.rs +++ b/src/app/store/records.rs @@ -1,10 +1,4 @@ -use bigdecimal::{BigDecimal, Context, RoundingMode}; -use std::sync::LazyLock; - -pub static ROUNDING_MODE: RoundingMode = RoundingMode::HalfEven; -/// Will use default precision (either 100 or ${RUST_BIGDECIMAL_DEFAULT_PRECISION}) -pub static DECIMAL_CONTEXT: LazyLock<Context> = - std::sync::LazyLock::new(|| Context::default().with_rounding_mode(ROUNDING_MODE)); +use bigdecimal::BigDecimal; type DateTime = chrono::DateTime<chrono::Utc>; @@ -111,10 +105,7 @@ impl EquityChangeEvent { /// Provides an estimate of the numerated change based on the cost basis /// of the equity and the quantity pub fn estimated_price(&self) -> BigDecimal { - DECIMAL_CONTEXT.multiply( - &self.equity_change_cost_basis, - &DECIMAL_CONTEXT.invert(&self.equity_change_quantity), - ) + self.equity_change_cost_basis.clone() / self.equity_change_quantity.clone() } /// Provides the quantity of the event relativized by the event type's score @@ -133,7 +124,7 @@ mod tests { use std::str::FromStr; fn nat(num: BigDecimal) -> BigDecimal { - num.with_scale_round(2_i64, ROUNDING_MODE) + num.with_scale_round(2_i64, bigdecimal::RoundingMode::HalfEven) } #[test] |
