pub fn shift_decimal(
int_part: &str,
frac_part: &str,
exp: i128,
) -> (String, String)
Expand description
Shifts digits between the integer and fractional part strings based on the given exponent.
ยงExamples
fn test(inp: (&str, &str, i128), out: (&str, &str)) {
assert_eq!(shift_decimal(inp.0, inp.1, inp.2), (out.0.to_string(), out.1.to_string()));
}
test(("123", "456", -5), ("0", "00123456"));
test(("123", "456", -4), ("0", "0123456"));
test(("123", "456", -3), ("0", "123456"));
test(("123", "456", -2), ("1", "23456"));
test(("123", "456", -1), ("12", "3456"));
test(("123", "456", 0), ("123", "456"));
test(("123", "456", 1), ("1234", "56"));
test(("123", "456", 2), ("12345", "6"));
test(("123", "456", 3), ("123456", "0"));
test(("123", "456", 4), ("1234560", "0"));
test(("123", "456", 5), ("12345600", "0"));
test(("100", "", -1), ("10", "0"));
test(("100", "", -2), ("1", "0"));
test(("100", "", -3), ("0", "1"));
test(("100", "", -4), ("0", "01"));
test(("", "001", 1), ("0", "01"));
test(("", "001", 2), ("0", "1"));
test(("", "001", 3), ("1", "0"));
test(("", "001", 4), ("10", "0"));