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

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

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

The canvas has been tainted by cross-origin data in chrome only -