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
}
}