Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49281
| References | <55bb3a29-7c8a-402c-8fb5-d12b5ee6330b@googlegroups.com> |
|---|---|
| From | Joshua Landau <joshua.landau.ws@gmail.com> |
| Date | 2013-06-26 23:14 +0100 |
| Subject | Re: Need help removing trailing zeros |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3905.1372284893.3114.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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