Jump to content

Currency: Difference between revisions

10 bytes removed ,  3 years ago
m
(Added Rust solution)
Line 1,276:
 
fn main() {
let hamburger = Currency::new(550,1005.50); //5,5
let milkshake = Currency::new(286,100); //2,.86);
let pre_tax = hamburger * 4_000_000_000_000_000 + milkshake * 2;
println!("Price before tax: {}", pre_tax);
Line 1,322:
impl Currency {
fn new(num: i64, den: i64f64) -> Self {
Self {
amount: BigRational::new(((num * 100.0) as i64).into(), den100.into())
}
}
 
fn calculate_tax(&self) -> Self {
let tax_val = BigRational::new(765.into(), 100.into());// 7.,65 -> 0.0765 after the next line
let amount = (&self.amount * tax_val).ceil() / BigInt::from(100);
Self {
Cookies help us deliver our services. By using our services, you agree to our use of cookies.