Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #40569

Re: Controlling number of zeros of exponent in scientific notation

Date 2013-03-05 15:56 -0500
From Dave Angel <davea@davea.name>
Subject Re: Controlling number of zeros of exponent in scientific notation
References <c2184b42-41be-4930-9501-361296df7679@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.2909.1362517009.2939.python-list@python.org> (permalink)

Show all headers | View raw


On 03/05/2013 03:09 PM, faraz@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Controlling number of zeros of exponent in scientific notation faraz@squashclub.org - 2013-03-05 12:09 -0800
  Re: Controlling number of zeros of exponent in scientific notation Dave Angel <davea@davea.name> - 2013-03-05 15:56 -0500
  Re: Controlling number of zeros of exponent in scientific notation Terry Reedy <tjreedy@udel.edu> - 2013-03-06 00:45 -0500
  Re: Controlling number of zeros of exponent in scientific notation Roy Smith <roy@panix.com> - 2013-03-06 09:03 -0500
    Re: Controlling number of zeros of exponent in scientific notation jmfauth <wxjmfauth@gmail.com> - 2013-03-06 07:16 -0800
  Re: Controlling number of zeros of exponent in scientific notation "Russ P." <Russ.Paielli@gmail.com> - 2013-03-06 11:11 -0800

csiph-web