use crate::{Currency, CurrencyLocale};
use std::ops::Mul;
impl<L: CurrencyLocale + Default> Mul<usize> for Currency<L> {
type Output = Self;
fn mul(self, rhs: usize) -> Self::Output {
let rhs = rhs as f32;
let tmp = (self.full as f32 + self.part as f32 / 100.0) * rhs;
let mut result: Currency<L> = tmp.into();
result.locale = self.locale;
result
}
}
impl<L: CurrencyLocale + Default> Mul<Currency<L>> for usize {
type Output = Currency<L>;
fn mul(self, rhs: Currency<L>) -> Self::Output {
rhs * self
}
}
impl<L: CurrencyLocale + Default> Mul<f32> for Currency<L> {
type Output = Self;
fn mul(self, rhs: f32) -> Self::Output {
let tmp = (self.full as f32 + self.part as f32 / 100.0) * rhs;
let mut result = Self::from(tmp);
result.negative = self.negative ^ rhs.is_sign_negative();
result.locale = self.locale;
result
}
}
impl<L: CurrencyLocale + Default> Mul<Currency<L>> for f32 {
type Output = Currency<L>;
fn mul(self, rhs: Currency<L>) -> Self::Output {
rhs * self
}
}
impl<L: CurrencyLocale + Default> Mul<f64> for Currency<L> {
type Output = Self;
fn mul(self, rhs: f64) -> Self::Output {
let tmp = (self.full as f64 + self.part as f64 / 100.0) * rhs;
let mut result = Self::from(tmp);
result.negative = self.negative ^ rhs.is_sign_negative();
result.locale = self.locale;
result
}
}
impl<L: CurrencyLocale + Default> Mul<Currency<L>> for f64 {
type Output = Currency<L>;
fn mul(self, rhs: Currency<L>) -> Self::Output {
rhs * self
}
}