diff --git a/Cargo.toml b/Cargo.toml index 188ae36..42394ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rust_dynamic" description = "Support for dynamically-typed values in run-time" -version = "0.26.0" +version = "0.27.0" edition = "2021" license-file = "LICENSE" repository = "https://github.com/vulogov/rust_dynamic" diff --git a/src/math.rs b/src/math.rs index 0a18f53..5a0de82 100644 --- a/src/math.rs +++ b/src/math.rs @@ -64,7 +64,7 @@ fn string_op_string_int(op: Ops, x: String, y: i64) -> String { fn string_op_string_float(op: Ops, x: String, y: f64) -> String { match op { Ops::Mul => x.repeat(y as usize), - Ops::Add => format!("{}{}", x, y), + Ops::Add => format!("{}{:.}", x, y), _ => x, } } diff --git a/tests/math-test.rs b/tests/math-test.rs index eecb34b..ecfefca 100644 --- a/tests/math-test.rs +++ b/tests/math-test.rs @@ -75,10 +75,18 @@ mod tests { } #[test] - fn test_textbuffer_add() { + fn test_textbuffer_add_string() { let mut x = Value::text_buffer("Hello".to_string()); let y = Value::from(" world").unwrap(); x = x + y; assert_eq!(x.cast_string().unwrap(), "Hello world"); } + + #[test] + fn test_textbuffer_add_float() { + let mut x = Value::text_buffer("Hello ".to_string()); + let y = Value::from(3.14).unwrap(); + x = x + y; + assert_eq!(x.cast_string().unwrap(), "Hello 3.14"); + } }