[PCBC-219] Floating point error in PHP Couchbase Library 1.1 Created: 09/Apr/13  Updated: 10/Apr/14  Resolved: 16/Apr/13

Status: Resolved
Project: Couchbase PHP client library
Component/s: library
Affects Version/s: 1.1.2
Fix Version/s: 1.1.4
Security Level: Public

Type: Bug Priority: Major
Reporter: Trond Norbye Assignee: Trond Norbye
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

$value = 50.00;
echo "getting value now... ";
Not 50.00.

Diving into the couchbase console, it is stored correctly. Something is wrong with the get method coming out of the PHP extension.
This is happening on any 2 decimal number with .00 as the extension. Caught this in an ecommerce application ... needless to say $ impact of giving someone $5011 instead of $50.00 is damaging.
Can anyone confirm this behavior in their environments?

Comment by Trond Norbye [ 16/Apr/13 ]
This was already fixed in some version before 1.1.4. I added a new testcase to verify this.

Comment by Shaun Tilford [ 11/Jun/13 ]
We are now running on 1.1.5 and still see the issue happening. Noted on over a dozen of our boxes here, both in development and production environments.
Comment by Trond Norbye [ 12/Jun/13 ]
What is your platform and PHP version so I can try to reproduce this?
Comment by Shaun Tilford [ 13/Jun/13 ]
PHP 5.4.12, CentOS release 5.6 (Final)
Comment by Trond Norbye [ 17/Jun/13 ]
I've had some trouble installing CentOS 5.6 locally, but so far I've tested it with success on:

Ubuntu 13.04
CentOS 6 (php from yum)
CentOS 5.7 (PHP 5.4.16)

I have get access to a CentOS 5.6 system to debug the problem there
Comment by Trond Norbye [ 17/Jun/13 ]
Hi, I finally got around to get access to a 5.6 box, but I doesn't fail there either:

[trondn@ip-10-36-176-84]~/compile/php-ext-couchbase/example% cat /etc/redhat-release
CentOS release 5.6 (Final)
[trondn@ip-10-36-176-84]~/compile/php-ext-couchbase/example% /opt/php/bin/php --version
PHP 5.4.16 (cli) (built: Jun 17 2013 16:44:15)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
[trondn@ip-10-36-176-84]~/compile/php-ext-couchbase/example% cat float.php

$cb = new Couchbase("localhost");

$val = 50.0;
var_dump($cb->set("foo", $val));
[trondn@ip-10-36-176-84]~/compile/php-ext-couchbase/example% /opt/php/bin/php -c couchbase.ini float.php
string(19) "5776353753026134016"

Comment by Matt Ingenthron [ 18/Jun/13 ]
Note, this was 64-bit, but the bug didn't indicate whether it was observed on 32-bit or 64-bit.
Comment by Sergey Avseyev [ 10/Apr/14 ]
FYI there is a patch related http://review.couchbase.org/35567

Generated at Wed Apr 16 11:18:08 CDT 2014 using JIRA 5.2.4#845-sha1:c9f4cc41abe72fb236945343a1f485c2c844dac9.