Determine precision and scale of particular number in Python

Posted by jrdioko on Stack Overflow See other posts from Stack Overflow or by jrdioko
Published on 2010-06-10T21:40:51Z Indexed on 2010/06/10 21:42 UTC
Read the original article Hit count: 229

Filed under:
|
|
|
|

I have a variable in Python containing a floating point number (e.g. num = 24654.123), and I'd like to determine the number's precision and scale values (in the Oracle sense), so 123.45678 should give me (8,5), 12.76 should give me (4,2), etc.

I was first thinking about using the string representation (via str or repr), but those fail for large numbers:

>>> num = 1234567890.0987654321
>>> str(num) = 1234567890.1
>>> repr(num) = 1234567890.0987654

© Stack Overflow or respective owner

Related posts about python

Related posts about string