REPOST: Re: set decimal place
Peter Hansen
peter at engcorp.com
Thu Dec 27 22:55:53 EST 2001
More information about the Python-list mailing list
Thu Dec 27 22:55:53 EST 2001
- Previous message (by thread): set decimal place
- Next message (by thread): REPOST: Re: set decimal place
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Chris Barker wrote: > > Peter Hansen wrote: > > > >>> 10.0/3 > > 3.3333333333333335 > > >>> round(10.0/3, 4) > > 3.3332999999999999 > > ^^^^^^^ > > This doesn't really solve the OP's problem. > > > The concept of "having 4 decimal places" is meaningless with > > floating point representations until you actually display the > > value as a formatted string. > > not completely. you might want to check if two values are the same to 4 > decimal places, in which case round should work just fine: > > >>> 10.0/3 == 10.00001/3 > 0 > >>> round(10.0/3,4) == round(10.00001/3,4) > 1 I don't know if this is guaranteed to work in all cases. Comparing floating point values directly is generally not a good idea, although I don't know whether this applies to rounded values, and if so how far you have to round them before it makes it safe. If it is safe, you have a valid point, but not likely what the OP wanted. -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com ========= WAS CANCELLED BY =======: Path: news.sol.net!spool1-milwwi.newsops.execpc.com!newsfeeds.sol.net!news-out.visi.com!hermes.visi.com!newsfeed.gamma.ru!Gamma.RU!nntp.kreonet.re.kr!feeder.kornet.net!news1.kornet.net!ua4canc3ll3r From: Peter Hansen <peter at engcorp.com> Newsgroups: comp.lang.python Subject: cmsg cancel <3C2BED49.E54CB73E at engcorp.com> Control: cancel <3C2BED49.E54CB73E at engcorp.com> Date: Mon, 31 Dec 2001 04:09:43 GMT Organization: A poorly-installed InterNetNews site Lines: 2 Message-ID: <cancel.3C2BED49.E54CB73E at engcorp.com> NNTP-Posting-Host: 211.57.49.2 X-Trace: news2.kornet.net 1009775433 27193 211.57.49.2 (31 Dec 2001 05:10:33 GMT) X-Complaints-To: usenet at news2.kornet.net NNTP-Posting-Date: Mon, 31 Dec 2001 05:10:33 +0000 (UTC) X-No-Archive: yes X-Unac4ncel: yes X-Commentary: I love NewsAgent 1.10 and the Sandblaster Cancel Engine Build 74 (19 March 1999) This message was cancelled from within Mozilla.
- Previous message (by thread): set decimal place
- Next message (by thread): REPOST: Re: set decimal place
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list