From owner-freebsd-questions@FreeBSD.ORG Wed Apr 12 13:37:12 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5BE0216A403 for ; Wed, 12 Apr 2006 13:37:12 +0000 (UTC) (envelope-from wmoran@collaborativefusion.com) Received: from mx00.pub.collaborativefusion.com (mx00.pub.collaborativefusion.com [206.210.89.199]) by mx1.FreeBSD.org (Postfix) with ESMTP id AE22A43D77 for ; Wed, 12 Apr 2006 13:37:03 +0000 (GMT) (envelope-from wmoran@collaborativefusion.com) Received: from vanquish.pgh.priv.collaborativefusion.com (vanquish.pgh.priv.collaborativefusion.com [192.168.2.61]) by wingspan with esmtp; Wed, 12 Apr 2006 09:37:01 -0400 id 00056419.443D027D.0001089C Date: Wed, 12 Apr 2006 09:37:01 -0400 From: Bill Moran To: Krzysztof Nakielski Message-Id: <20060412093701.0309d4a6.wmoran@collaborativefusion.com> In-Reply-To: <20060412100917.GA1406@nakiel.dyndns.org> References: <20060412100917.GA1406@nakiel.dyndns.org> Organization: Collaborative Fusion X-Mailer: Sylpheed version 2.2.0 (GTK+ 2.8.12; i386-portbld-freebsd6.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: freebsd-questions@freebsd.org Subject: Re: round() problem X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Apr 2006 13:37:12 -0000 On Wed, 12 Apr 2006 12:09:17 +0200 Krzysztof Nakielski wrote: > Hi, > > I am having problem with round() function in php, python, mysql. I am > not sure if thats FreeBSD issue. I receive the same results on 4.11, 5.4 > and 6.0. > > php (4.4.1, 5.1.2): > %php -r 'print round(8.075, 2) ."\n";' > 8.07 > %php -r 'print round(8.085, 2) ."\n";' > 8.09 > %php -r 'print round(0.075, 2) ."\n";' > 0.08 [snip duplicate examples in MySQL and Python] Have you compared these results to other POSIX systems? The problem is in the way that real numbers are implemented. If you do some searches, you'll find many, many discussions of this. Simple fact is that the behaviour under these circumstances is not what you think it is. This kind of thing is the reason that most languages have high-precision floating point libraries available. -- Bill Moran Collaborative Fusion Inc.