Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Apr 2006 09:37:01 -0400
From:      Bill Moran <wmoran@collaborativefusion.com>
To:        Krzysztof Nakielski <nakiel@nakiel.net>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: round() problem
Message-ID:  <20060412093701.0309d4a6.wmoran@collaborativefusion.com>
In-Reply-To: <20060412100917.GA1406@nakiel.dyndns.org>
References:  <20060412100917.GA1406@nakiel.dyndns.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 12 Apr 2006 12:09:17 +0200
Krzysztof Nakielski <nakiel@nakiel.net> 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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060412093701.0309d4a6.wmoran>