Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.058 X-Spam-Evidence: '*H*': 0.89; '*S*': 0.01; 'float': 0.07; 'cc:addr :python-list': 0.11; '23,': 0.16; 'cc:name:python list': 0.16; 'number?': 0.16; 'other,': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'mon,': 0.24; 'cc:2**0': 0.24; 'possibly': 0.26; 'van': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'steven': 0.31; 'received:google.com': 0.35; 'there': 0.35; 'subject:?': 0.36; 'pm,': 0.38; 'mar': 0.68; 'lose': 0.68; '2015': 0.84; 'subject:Best': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=wX5TU/WG7l/K63sLuaSUdhdmYhvtd5DNsR34xBE2VWg=; b=ZORuSzZfJ4LNBsSqbC4P7PiBx2yKGgyRqkn+ZNwts60BVzcq4Qoy82UuD8xEkvTuzQ a+YTRIXR3oc4iQO4sE7yymvc7Al5o4b0+2CN3e74S4sZ27HMDa94EYdingzUKPiSpGcT 1Q/B1hXoMsy5WbRyb/x9UhtQHpV7dHbKWJ6hRKd2u8aV1kkJPSFUD2C4M4tZ6ck9696g EVtsOQ0M+cAIDwPs470/yv9JrYKYguhiw+WJbtdnFbrDvCbhBjuIhVEGhNoRA5Bve9Kt 7BbowosIrFNt8B0MA/8S1zfzi/phz52LhJwAHjVJtqGLLoEUDeitd7JgoGZJxGlTc6sU 5ziQ== MIME-Version: 1.0 X-Received: by 10.170.221.193 with SMTP id n184mr8585324ykf.69.1427247583104; Tue, 24 Mar 2015 18:39:43 -0700 (PDT) In-Reply-To: References: <55100c7a$0$13004$c3e8da3$5496439d@news.astraweb.com> Date: Tue, 24 Mar 2015 21:39:43 -0400 Subject: Re: Best way to calculate fraction part of x? From: Jason Swails Cc: python list Content-Type: multipart/alternative; boundary=001a113a668e329471051212f939 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1427247586 news.xs4all.nl 2841 [2001:888:2000:d::a6]:60711 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:87916 --001a113a668e329471051212f939 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, Mar 23, 2015 at 8:38 PM, Emile van Sebille wrote: > On 3/23/2015 5:52 AM, Steven D'Aprano wrote: > > Are there any other, possibly better, ways to calculate the fractional >> part >> of a number? >> > > float (("%6.3f" % x)[-4:]) =E2=80=8BIn general you lose a lot of precision this way...=E2=80=8B --001a113a668e329471051212f939 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

<= /div>

On Mon, Mar = 23, 2015 at 8:38 PM, Emile van Sebille <emile@fenx.com> wrote:<= br>
On 3/23/2015 5:52 AM, St= even D'Aprano wrote:

Are there any other, possibly better, ways to calculate the fractional part=
of a number?

float (("%6.3f" % x)[-4:])

=E2=80=8BI= n general you lose a lot of precision this way...=E2=80=8B
--001a113a668e329471051212f939--