2023年9月25日 星期一

[python] Remove the 0s after decimal point .

By using sympy.sympify(), I can parse user input math string input eg:(1+2.2)*3
but it may return a result with 0s in the tail, eg:3.000000

to remove these .0 s

strVal = strVal if strVal.find('.') == -1 else strVal.strip('0')