optionstratlib_core/model/
positive_ext.rs1use crate::model::utils::ToRound;
13use positive::Positive;
14use rust_decimal::Decimal;
15
16impl ToRound for Positive {
17 fn round(&self) -> Decimal {
18 Positive::round(self).to_dec()
19 }
20
21 fn round_to(&self, decimal_places: u32) -> Decimal {
22 Positive::round_to(self, decimal_places).to_dec()
23 }
24}
25
26#[cfg(test)]
27mod tests {
28 use super::*;
29 use positive::pos_or_panic;
30
31 #[test]
32 fn test_to_round_trait() {
33 let p = pos_or_panic!(1.567);
34 assert_eq!(p.round(), Decimal::from(2));
35 assert_eq!(p.round_to(1), Decimal::new(16, 1));
36 }
37}