metawards.utils.safe_eval_number

metawards.utils.safe_eval_number(s: Union[float, int, str]) float[source]

Convert ‘s’ to a number. This supports normal floats, but also simple maths expressions like 1/1.2, plus anything that ends with a “%” is recognised as a percentage

Examples

safe_eval_number(0.3) -> 0.3 safe_eval_number(“5%”) -> 0.05 safe_eval_number(“1/4”) -> 0.25 safe_eval_number(“(30+100)%) -> 1.3