Controlling number of zeros of exponent in scientific notation
davea at davea.name
Tue Mar 5 21:56:26 CET 2013
On 03/05/2013 03:09 PM, faraz at squashclub.org wrote:
> Instead of:
> I need:
> 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 ?
More information about the Python-list