1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use crate::{Currency, CurrencyLocale};
use std::ops::Div;

impl<L: CurrencyLocale + Default> Div<usize> for Currency<L> {
    type Output = Self;

    fn div(self, rhs: usize) -> Self::Output {
        let mut tmp = self.full * 100 + self.part as usize;
        tmp /= rhs;
        let part = (tmp % 100) as u8;
        let full = tmp / 100;

        Self::new(self.negative, full, part, self.locale)
    }
}

impl<L: CurrencyLocale + Default> Div<f32> for Currency<L> {
    type Output = Self;

    fn div(self, rhs: f32) -> Self::Output {
        let mut tmp = self.full as f32 + self.part as f32 / 100.0;
        tmp /= rhs;

        let mut result = Self::from(tmp);
        result.negative = self.negative ^ rhs.is_sign_negative();
        result.locale = self.locale;
        result
    }
}

impl<L: CurrencyLocale + Default> Div<f64> for Currency<L> {
    type Output = Self;

    fn div(self, rhs: f64) -> Self::Output {
        let mut tmp = self.full as f64 + self.part as f64 / 100.0;
        tmp /= rhs;

        let mut result = Self::from(tmp);
        result.negative = self.negative ^ rhs.is_sign_negative();
        result.locale = self.locale;
        result
    }
}