python - Round Sympy Mul with Units -


i'm trying round output of solve evaluation has units attached it.

for example:

solve(eq(x, 22/7 * seconds), x)[0] 

outputs:

3.14285714285714*s 

is there way round 3.14*s while keeping s?

sympy expressions have .evalf() method approximate numbers. accepts optional parameter n, specifies number of digits approximate expression contain.

supposing expression contained in expr variable:

in [5]: expr out[5]: 3.14285714285714⋅s  in [6]: expr.evalf(n=10) out[6]: 3.142857143⋅s  in [7]: expr.evalf(n=2) out[7]: 3.1⋅s  in [8]: expr.evalf(n=3) out[8]: 3.14⋅s 

Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

javascript - Confirm a form & display message if form is valid with JQuery -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -