Ostico / PhpOrient

PhpOrient - Official Php driver based on the binary protocol of OrientDB.
Other
68 stars 37 forks source link

Double losing precision when saved to the database #48

Closed andreyvk closed 8 years ago

andreyvk commented 8 years ago

Hi @Ostico,

I am losing precision on double values, when I save data to the database. Im on OrientDB 2.1.2 and the latest PhpOrient. I am also using Ubuntu 14 (x64) with PHP 5.5

Here's the test schema:

create class TestPrecision extends BaseV
create property TestPrecision.number double

Executing the following truncates the number

$client = new \PhpOrient\PhpOrient( 'localhost', 2424 );
$client->username = 'user';
$client->password = 'pass';
$client->connect();
$client->dbOpen( 'test', 'user', 'pass' );

//create record
$odata= [ "number" => 33533.1424 ];
$rec = ( new Record() )->setOData( $odata )->setRid( new ID( /* CLUSTER ID */ ) ); 
$rec = $client->recordCreate( $rec );

//re-load record
$record = $client->loadRecord( $rec->getRid() )[0]; 

//output
echo "Number is: " . $record["number"]; //the number printed out is 33533.14

PS - I've tried inserting data from the Studio and precision was fine. Therefore, I think there's something inside the library which is causing number to round up.