Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python,': 0.02; 'happen.': 0.09; 'output,': 0.09; 'subject:number': 0.09; 'zeros': 0.09; '"0"': 0.16; 'converted,': 0.16; 'need:': 0.16; 'precision,': 0.16; 'wrote:': 0.17; 'string,': 0.17; 'appropriate': 0.20; 'variable': 0.20; 'produces': 0.22; 'insert': 0.23; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'values': 0.26; 'converting': 0.27; 'closer': 0.29; 'end,': 0.29; 'convert': 0.29; 'could': 0.32; 'zero': 0.33; 'to:addr:python-list': 0.33; 'version': 0.34; 'wrong': 0.34; 'problem,': 0.35; 'pm,': 0.35; 'but': 0.36; 'characters': 0.36; 'two': 0.37; 'subject:: ': 0.38; 'supports': 0.38; 'some': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'your': 0.60; 'range': 0.60; 'show': 0.63; 'of:': 0.65; 'useful.': 0.65; 'received:74.208': 0.71 Date: Tue, 05 Mar 2013 15:56:26 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130221 Thunderbird/17.0.3 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Controlling number of zeros of exponent in scientific notation References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:NBA2smULR77v4+fKcVacIWmV9TENH+NWZAXy9myGp9l RRL6qXqYn8CBWXTVQ4RtqvED3n/f2QuJ88YxfSB+UjWHy+6Reu GQJLIeB+vlZFw/Lxr/L8bJZJ2IXbh3How/Tg8BclmiGBWbNfpb HNJUbuluwX6oJ5FDOsR7vgSsYgg5mTYURs3fMG4YQlNivaMeLt W34lnjA5trgk5PFy9d9cX8bFsc5ma7M98wAdDXZmV9GZ4vgcyk 547uX8N5kRFIxI4zCqAlJdE3udZl8sTgdk+1pN8l6homWRTuCN 5qvtUMw51oP/S6czxeuZo3PEI9dtq7afqzN+vHccRBUG2S8zw= = X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362517009 news.xs4all.nl 6946 [2001:888:2000:d::a6]:58046 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40569 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