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


Groups > comp.lang.python > #88089

Re: Best way to calculate fraction part of x?

From Emile van Sebille <emile@fenx.com>
Subject Re: Best way to calculate fraction part of x?
Date 2015-03-26 13:48 -0700
References <55100c7a$0$13004$c3e8da3$5496439d@news.astraweb.com> <meqbmo$4rb$1@ger.gmane.org> <CAEk9e3o7fGcJw=V+C1TwLJ3+6mVQ6c1ShCUca4QAtp6hK1BVjA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.214.1427402951.10327.python-list@python.org> (permalink)

Show all headers | View raw


On 3/24/2015 6:39 PM, Jason Swails wrote:
>
>
> On Mon, Mar 23, 2015 at 8:38 PM, Emile van Sebille <emile@fenx.com

<snip>

>     float (("%6.3f" % x)[-4:])
>
>
> ​In general you lose a lot of precision this way...​
>

Even more if you use %6.1 -- but feel free to flavor to taste.   :)

Emile


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


Thread

Best way to calculate fraction part of x? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-23 23:52 +1100
  Re: Best way to calculate fraction part of x? Skip Montanaro <skip.montanaro@gmail.com> - 2015-03-23 08:02 -0500
  Re: Best way to calculate fraction part of x? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-23 13:11 +0000
  Re: Best way to calculate fraction part of x? wxjmfauth@gmail.com - 2015-03-23 06:17 -0700
  Re: Best way to calculate fraction part of x? Emile van Sebille <emile@fenx.com> - 2015-03-23 17:38 -0700
  Re: Best way to calculate fraction part of x? Jason Swails <jason.swails@gmail.com> - 2015-03-24 21:39 -0400
  Re: Best way to calculate fraction part of x? Emile van Sebille <emile@fenx.com> - 2015-03-26 13:48 -0700
  Re: Best way to calculate fraction part of x? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-03-26 21:59 +0000
  Re: Best way to calculate fraction part of x? Russell Owen <rowen@uw.edu> - 2015-03-26 15:02 -0700

csiph-web