REPOST: Re: set decimal place

Chris Barker chrishbarker at attbi.com
Thu Dec 27 14:40:58 EST 2001


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

of course, you would more often want to compare given n significatn
figures instaead, in whioch case you can write a function with log, etc
that will do it for you. See the archives for a discussion of this, and
some posted code.

-Chris




-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at attbi.net                ---           ---           ---
                                     ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------

========= WAS CANCELLED BY =======:
Path: news.sol.net!spool0-milwwi.newsops.execpc.com!newsfeeds.sol.net!news-out.visi.com!hermes.visi.com!newsxfer.interpacket.net!news-xfer.nuri.net!feeder.kornet.net!news1.kornet.net!ua4canc3ll3r
From: Chris Barker <chrishbarker at attbi.com>
Newsgroups: comp.lang.python
Subject: cmsg cancel <3C2B794A.800A94E5 at attbi.com>
Control: cancel <3C2B794A.800A94E5 at attbi.com>
Date: Mon, 31 Dec 2001 03:16:36 GMT
Organization: A poorly-installed InterNetNews site
Lines: 2
Message-ID: <cancel.3C2B794A.800A94E5 at attbi.com>
NNTP-Posting-Host: 211.57.49.2
X-Trace: news2.kornet.net 1009775626 27193 211.57.49.2 (31 Dec 2001 05:13:46 GMT)
X-Complaints-To: usenet at news2.kornet.net
NNTP-Posting-Date: Mon, 31 Dec 2001 05:13:46 +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.



More information about the Python-list mailing list