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


Groups > comp.lang.python > #49281

Re: Need help removing trailing zeros

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <joshua.landau.ws@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.097
X-Spam-Evidence '*H*': 0.82; '*S*': 0.02; 'subject:help': 0.08; 'seemed': 0.09; 'cc:addr:python-list': 0.11; 'calculator': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'skip:" 30': 0.26; 'post': 0.26; 'code:': 0.26; 'header:In-Reply- To:1': 0.27; 'tried': 0.27; 'appreciated.': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'work.': 0.31; 'anyone': 0.31; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'should': 0.36; 'skip:. 20': 0.38; 'needed': 0.38; 'making': 0.63; 'subject:Need': 0.64; 'to:addr:gmail.com': 0.65; 'either:': 0.91; 'hate': 0.91; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=CCHAP7X3FVN+KKCMYnmvIQY4hx/SdhouMydOIEolXz8=; b=SbDdwE95+8Iez2IiwMVPfd2eTZueA4CIfW8EHCcCzDNSyWMunG9Me6vpkbFovK1jmo V/NtA9vKMMitw68Mf6Xa4MNhYGgoP+Pk5MdXWJxspMZpIds6LUqi9tMWY0bQpBDbxxNK B5oWLSyX5E4Y7m7IwumZHqoUGMQn5UQxSR1HG+naAdCv3kF6vFZXPJx55SUEUrASS48k VJDugaTlCuAqIwaNX8bcoyGtp0JUGBFX/NNceT3tT0uVddicedTWTFML6Sc+ZIccVnTt 8srbKz9IpbqMTXWNsQtjtnEePTn/ZmIE035ZzQl3w1Ox0rsZczv0epdqSI2F2cD1WRO5 ZibA==
X-Received by 10.152.45.65 with SMTP id k1mr2774138lam.78.1372284885163; Wed, 26 Jun 2013 15:14:45 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <55bb3a29-7c8a-402c-8fb5-d12b5ee6330b@googlegroups.com>
References <55bb3a29-7c8a-402c-8fb5-d12b5ee6330b@googlegroups.com>
From Joshua Landau <joshua.landau.ws@gmail.com>
Date Wed, 26 Jun 2013 23:14:05 +0100
Subject Re: Need help removing trailing zeros
To bandcamp57@gmail.com
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3905.1372284893.3114.python-list@python.org> (permalink)
Lines 18
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1372284893 news.xs4all.nl 15878 [2001:888:2000:d::a6]:37657
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:49281

Show key headers only | View raw


On 26 June 2013 23:02,  <bandcamp57@gmail.com> wrote:
> Hello, i'm making a calculator and I want to be able to use decimals but I don't like it when it comes out as ex.12.0 when it should be 12. I tried using .rstrip("0".rstrip(".") but that never seemed to work. If anyone has a solution please let me know, all help is greatly appreciated.
>
> Code:
<LOTS 'O CODE>

Was that really necessary?

All you needed to give use was "print(1.0)"; why post so much?

Either:
"{:g}".format(1.0)

or, if you hate scientific notation:
"{:f}".format(1.0).rstrip(".0")

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


Thread

Need help removing trailing zeros bandcamp57@gmail.com - 2013-06-26 15:02 -0700
  Re: Need help removing trailing zeros Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-26 23:14 +0100
  Re: Need help removing trailing zeros PyNoob <bandcamp57@gmail.com> - 2013-06-26 15:21 -0700
    Re: Need help removing trailing zeros Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-27 00:05 +0100
  Re: Need help removing trailing zeros PyNoob <bandcamp57@gmail.com> - 2013-06-26 19:30 -0700

csiph-web