Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66485
| References | (4 earlier) <mailman.6978.1392461388.18130.python-list@python.org> <df9f242f-b438-4159-b605-4be5e937aaec@googlegroups.com> <mailman.7011.1392485048.18130.python-list@python.org> <9c1b03cb-c607-4784-aaec-78616988c302@googlegroups.com> <877d1ddd-39d8-4ede-8dff-addade1c57cd@googlegroups.com> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2014-02-15 14:34 -0700 |
| Subject | Re: decimal numbers |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.7024.1392500128.18130.python-list@python.org> (permalink) |
On Sat, Feb 15, 2014 at 11:57 AM, Luke Geelen <luke.geelen@gmail.com> wrote:
> hey, is it possible to remove the .0 if it is a valua without something behind the poit (like 5.0 gets 5 but 9.9 stays 9.9
The ':g' format specifier will trim off trailing zeroes, e.g.:
>>> '{:g}'.format(5.0)
'5'
It also switches to exponential notation if the scale of the number is
greater than the specified precision (default 6):
>>> '{:g}'.format(5000000.0)
'5e+06'
You can read up on string formatting for more details:
http://docs.python.org/3/library/string.html#formatstrings
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
decimal numbers luke.geelen@gmail.com - 2014-02-15 01:18 -0800
Re: decimal numbers Luke Geelen <luke.geelen@gmail.com> - 2014-02-15 01:19 -0800
Re: decimal numbers "Frank Millman" <frank@chagford.com> - 2014-02-15 12:04 +0200
Re: decimal numbers Luke Geelen <luke.geelen@gmail.com> - 2014-02-15 02:32 -0800
Re: decimal numbers "Frank Millman" <frank@chagford.com> - 2014-02-15 12:49 +0200
Re: decimal numbers Luke Geelen <luke.geelen@gmail.com> - 2014-02-15 09:17 -0800
Re: decimal numbers Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-15 10:23 -0700
Re: decimal numbers Luke Geelen <luke.geelen@gmail.com> - 2014-02-15 09:42 -0800
Re: decimal numbers Luke Geelen <luke.geelen@gmail.com> - 2014-02-15 10:57 -0800
Re: decimal numbers Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-15 19:06 +0000
Re: decimal numbers Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-15 19:43 +0000
Re: decimal numbers Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-15 14:34 -0700
Re: decimal numbers Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-16 02:30 +0000
Re: decimal numbers Chris Angelico <rosuav@gmail.com> - 2014-02-16 13:36 +1100
Re: decimal numbers "Frank Millman" <frank@chagford.com> - 2014-02-15 12:56 +0200
Re: decimal numbers Chris Angelico <rosuav@gmail.com> - 2014-02-15 21:13 +1100
Re: decimal numbers Laurent Pointal <laurent.pointal@free.fr> - 2014-02-15 15:52 +0100
Re: decimal numbers Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-15 10:20 -0700
Re: decimal numbers wxjmfauth@gmail.com - 2014-02-16 04:19 -0800
csiph-web