python - Convert number to string scientific notation fixed length -


i have normal float number such "1234.567" or "100000". convert string such precision fixed , number in scientific notation. example, 5 digits, results "1.2346e003 , "1.0000e005", respectively. builtin decimal number -> string functions round if can, second number "1e005" when want more digits. undesirable since need numbers same length.

is there "pythonic" way without resorting complicated string operations?

precision = 2 number_to_convert = 10000 print "%0.*e"%(precision,number_to_convert) 

is asking for?


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c# - Avoiding duplicate methods for Task and Task<T> -

javascript - Which segment of a polyline was clicked? -