|
@@ -124,6 +124,9 @@ impl ToString for Amount {
|
|
|
left,
|
|
|
right
|
|
|
)
|
|
|
+ .trim_end_matches("0")
|
|
|
+ .trim_end_matches(".")
|
|
|
+ .to_owned()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -138,7 +141,7 @@ mod test {
|
|
|
precision: 4,
|
|
|
};
|
|
|
let amount = usd.new_amount(1022100);
|
|
|
- assert_eq!(amount.to_string(), "102.2100");
|
|
|
+ assert_eq!(amount.to_string(), "102.21");
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
@@ -147,17 +150,18 @@ mod test {
|
|
|
id: 1,
|
|
|
precision: 8,
|
|
|
};
|
|
|
- assert_eq!(btc.new_amount(1022100).to_string(), "0.01022100");
|
|
|
- assert_eq!(btc.new_amount(10).to_string(), "0.00000010");
|
|
|
- assert_eq!(btc.new_amount(10000000).to_string(), "0.10000000");
|
|
|
- assert_eq!(btc.new_amount(100000000).to_string(), "1.00000000");
|
|
|
+ assert_eq!(btc.new_amount(1022100).to_string(), "0.010221");
|
|
|
+ assert_eq!(btc.new_amount(10).to_string(), "0.0000001");
|
|
|
+ assert_eq!(btc.new_amount(10000000).to_string(), "0.1");
|
|
|
+ assert_eq!(btc.new_amount(100000000).to_string(), "1");
|
|
|
assert_eq!(
|
|
|
btc.new_amount(100000000)
|
|
|
.checked_add(&btc.new_amount(100000000))
|
|
|
.unwrap()
|
|
|
.to_string(),
|
|
|
- "2.00000000"
|
|
|
+ "2",
|
|
|
);
|
|
|
+ assert_eq!(btc.new_amount(1000000000).to_string(), "10");
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
@@ -167,16 +171,16 @@ mod test {
|
|
|
precision: 8,
|
|
|
};
|
|
|
let parsed_amount = Amount::from_human(btc, "0.1").expect("valid amount");
|
|
|
- assert_eq!(parsed_amount.to_string(), "0.10000000");
|
|
|
+ assert_eq!(parsed_amount.to_string(), "0.1");
|
|
|
let parsed_amount = Amount::from_human(btc, "-0.1").expect("valid amount");
|
|
|
- assert_eq!(parsed_amount.to_string(), "-0.10000000");
|
|
|
+ assert_eq!(parsed_amount.to_string(), "-0.1");
|
|
|
let parsed_amount = Amount::from_human(btc, "-0.000001").expect("valid amount");
|
|
|
- assert_eq!(parsed_amount.to_string(), "-0.00000100");
|
|
|
+ assert_eq!(parsed_amount.to_string(), "-0.000001");
|
|
|
let parsed_amount = Amount::from_human(btc, "-0.000000001").expect("valid amount");
|
|
|
- assert_eq!(parsed_amount.to_string(), "0.00000000");
|
|
|
+ assert_eq!(parsed_amount.to_string(), "0");
|
|
|
let parsed_amount = Amount::from_human(btc, "0.000001").expect("valid amount");
|
|
|
- assert_eq!(parsed_amount.to_string(), "0.00000100");
|
|
|
+ assert_eq!(parsed_amount.to_string(), "0.000001");
|
|
|
let parsed_amount = Amount::from_human(btc, "-0.000000100001").expect("valid amount");
|
|
|
- assert_eq!(parsed_amount.to_string(), "-0.00000010");
|
|
|
+ assert_eq!(parsed_amount.to_string(), "-0.0000001");
|
|
|
}
|
|
|
}
|