doing arithmetic upto two significant figures in Python?

Posted by user248237 on Stack Overflow See other posts from Stack Overflow or by user248237
Published on 2010-05-04T00:03:27Z Indexed on 2010/05/04 0:08 UTC
Read the original article Hit count: 187

Filed under:
|
|
|

I have two floats in Python that I'd like to subtract, i.e.

v1 = float(value1) v2 = float(value2) diff = v1 - v2

I want "diff" to be computed upto two significant figures, that is compute it using %.2f of v1 and %.2f of v2. How can I do this? I know how to print v1 and v2 up to two decimals, but not how to do arithmetic like that.

thanks.

© Stack Overflow or respective owner

Related posts about python

Related posts about numpy