scientific notation - How to get value after e for python floats -


i enter values in scientific notation (e.g. 3.472e-07) floats in python. there simple way access exponent of given float in python?

e.g. given x = 4.7820012347239297234e-7, there way value after e (in case, -7).

thanks!

(1) take log of number , round value accordingly.

for val in [12345678901234567890.0, .0000004782]:     logval = math.log10(val)     print val, logval, round(logval - (0.5 if logval<0 else 0)) 

(2) convert string, grab first occurrence of "e" from right end, , take remainder of string.

for val in [12345678901234567890.0, .0000004782]:     valstr = "{0:e}".format(val)     epos = valstr.rfind('e')     exponent = valstr[epos+1:]     print int(exponent) 

would either of work you?


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -