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


Groups > comp.lang.python > #90090

Re: Converting 5.223701009526849e-05 to 5e-05

From Alexander Blinne <news@blinne.net>
Newsgroups comp.lang.python
Subject Re: Converting 5.223701009526849e-05 to 5e-05
Date 2015-05-07 10:00 +0200
Organization Aioe.org NNTP Server
Message-ID <mif63i$k9a$1@speranza.aioe.org> (permalink)
References <87vbgakrlr.fsf@Equus.decebal.nl> <85mw1mdpfd.fsf@benfinney.id.au> <mailman.54.1430642933.12865.python-list@python.org>

Show all headers | View raw


Am 03.05.2015 um 10:48 schrieb Ben Finney:
> That's not as clear as it could be. Better is to be explicit about
> choosing “exponential” format::
> 
>     >>> foo = 5.223701009526849e-05
>     >>> "{foo:5.0e}".format(foo=foo)
>     '5e-05'
> 

Or even better the "general" format, which also works for 0.9999:

    >>> "{foo:.1g}".format(foo=5.223701009526849e-5)
    '5e-05'
    >>> "{foo:.1g}".format(foo=0.9999)
    '1'

I guess all roads lead to Rome...

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


Thread

Converting 5.223701009526849e-05 to 5e-05 Cecil Westerhof <Cecil@decebal.nl> - 2015-05-03 10:11 +0200
  Re: Converting 5.223701009526849e-05 to 5e-05 Ben Finney <ben+python@benfinney.id.au> - 2015-05-03 18:40 +1000
    Re: Converting 5.223701009526849e-05 to 5e-05 Cecil Westerhof <Cecil@decebal.nl> - 2015-05-03 11:22 +0200
      Re: Converting 5.223701009526849e-05 to 5e-05 Chris Angelico <rosuav@gmail.com> - 2015-05-03 19:51 +1000
        Re: Converting 5.223701009526849e-05 to 5e-05 Cecil Westerhof <Cecil@decebal.nl> - 2015-05-03 12:02 +0200
          Re: Converting 5.223701009526849e-05 to 5e-05 Chris Angelico <rosuav@gmail.com> - 2015-05-03 20:57 +1000
      Re: Converting 5.223701009526849e-05 to 5e-05 Dave Angel <davea@davea.name> - 2015-05-03 07:34 -0400
  Re: Converting 5.223701009526849e-05 to 5e-05 Ben Finney <ben+python@benfinney.id.au> - 2015-05-03 18:48 +1000
    Re: Converting 5.223701009526849e-05 to 5e-05 Alexander Blinne <news@blinne.net> - 2015-05-07 10:00 +0200

csiph-web