Function string_template_plus::transformers::calc
source · pub fn calc(val: &str, args: Vec<&str>) -> Result<String, TransformerError>
Expand description
Airthmatic calculations, the value needs to be float. e.g. {val:calc(+1)}
will add 1 to the value. The order of calculation is left to right.
assert_eq!(calc("1.24", vec!["+1"])?, "2.24");
assert_eq!(calc("1", vec!["+1*2^2"])?, "16");
assert_eq!(calc("1.24", vec!["+1", "-1"])?, "2.24,0.24");