Bug #75920 [Opn->Nab]: precision problem with decimals read from sql server

From: Date: Tue, 06 Feb 2018 06:30:24 +0000
Subject: Bug #75920 [Opn->Nab]: precision problem with decimals read from sql server
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213825@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75920&edit=1 ID: 75920 Updated by: rasmus@php.net Reported by: km dot wrona at gmail dot com Summary: precision problem with decimals read from sql server -Status: Open +Status: Not a bug Type: Bug Package: PDO DBlib Operating System: Alpine PHP Version: 7.1.14 Block user comment: N Private report: N New Comment: Floating point values have a limited precision. Hence a value might not have the same string representation after any processing. That also includes writing a floating point value in your script and directly printing it without any mathematical operations. If you would like to know more about "floats" and what IEEE 754 is, read this: http://www.floating-point-gui.de/ Thank you for your interest in PHP. 1.6 can't be represented exactly as a floating point value. Previous Comments: ------------------------------------------------------------------------ [2018-02-05 13:29:42] km dot wrona at gmail dot com Description: ------------ The number is not represented properly when the column is defined as decimal. Test script: --------------- var_dump($this->selectRaw('CAST(\'1.6\' as decimal(10,2)) as dec, CAST(\'1.6\' as float) as flo')->limit(1)->get()); exit; array(1) { [0]=> object(stdClass)#789 (2) { ["dec"]=> float(1.5999999999999) ["flo"]=> float(1.6) } } //default behaviour ["dec"]=> float(1.5999999999999) //with //ini_set('precision', 25); //ini_set('serialize_precision', 25); ["dec"]=> float(1.599999999999909050529823) Expected result: ---------------- 1.6 no matter if decimal or float ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75920&edit=1

« previous php.bugs (#213825) next »