On 03/05/2013 03:09 PM, fa...@squashclub.org wrote:
Instead of:

1.8e-04

I need:

1.8e-004

So two zeros before the 4, instead of the default 1.


You could insert a zero two characters before the end,

num = "1.8e-04"
num = num[:-2] + "0" + num[-2:]

But to get closer to your problem, could you give some background? What version of Python, what type is this "number" before you convert it to a string, how are you converting it?

If the type supports variable precision, then what precision range are you interested in supporting?

A sample program that produces the wrong output, but going through all the appropriate steps would be useful. Show what values you start with, how they get converted, and what you'd like to happen. What do you want to happen if the number is actually 1.8e-178 ? How about 1.8e-1488 ?



--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to