久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='4sDZQ'><style id='4sDZQ'><dir id='4sDZQ'><q id='4sDZQ'></q></dir></style></legend>

  • <small id='4sDZQ'></small><noframes id='4sDZQ'>

    <i id='4sDZQ'><tr id='4sDZQ'><dt id='4sDZQ'><q id='4sDZQ'><span id='4sDZQ'><b id='4sDZQ'><form id='4sDZQ'><ins id='4sDZQ'></ins><ul id='4sDZQ'></ul><sub id='4sDZQ'></sub></form><legend id='4sDZQ'></legend><bdo id='4sDZQ'><pre id='4sDZQ'><center id='4sDZQ'></center></pre></bdo></b><th id='4sDZQ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='4sDZQ'><tfoot id='4sDZQ'></tfoot><dl id='4sDZQ'><fieldset id='4sDZQ'></fieldset></dl></div>

    <tfoot id='4sDZQ'></tfoot>
      <bdo id='4sDZQ'></bdo><ul id='4sDZQ'></ul>

      1. PHP PDO 查詢(xún)?yōu)?FLOAT 字段返回不準(zhǔn)確的值

        PHP PDO query returns inaccurate value for FLOAT fields(PHP PDO 查詢(xún)?yōu)?FLOAT 字段返回不準(zhǔn)確的值)

            <small id='3outW'></small><noframes id='3outW'>

            • <tfoot id='3outW'></tfoot>
                <legend id='3outW'><style id='3outW'><dir id='3outW'><q id='3outW'></q></dir></style></legend>
                • <bdo id='3outW'></bdo><ul id='3outW'></ul>
                    <tbody id='3outW'></tbody>

                  <i id='3outW'><tr id='3outW'><dt id='3outW'><q id='3outW'><span id='3outW'><b id='3outW'><form id='3outW'><ins id='3outW'></ins><ul id='3outW'></ul><sub id='3outW'></sub></form><legend id='3outW'></legend><bdo id='3outW'><pre id='3outW'><center id='3outW'></center></pre></bdo></b><th id='3outW'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='3outW'><tfoot id='3outW'></tfoot><dl id='3outW'><fieldset id='3outW'></fieldset></dl></div>
                  本文介紹了PHP PDO 查詢(xún)?yōu)?FLOAT 字段返回不準(zhǔn)確的值的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我猜這之前已經(jīng)出現(xiàn)過(guò),但我找不到我的問(wèn)題的答案.這是一個(gè)小代碼片段:

                   $stmt = $this ->分貝->詢(xún)問(wèn)("選擇`字段`從`表`在哪里(`ID` = 33608)");var_dump($stmt -> fetch());

                  這是我得到的結(jié)果:

                   array(1) { ["Field"]=>浮動(dòng)(1.7999999523163)}

                  然而,MySQL數(shù)據(jù)庫(kù)中的數(shù)據(jù)是1.8.該字段的類(lèi)型是 float(7,4).$this->db 是一個(gè) PDO 對(duì)象.我最近遷移到 PDO(從 AdoDB),并且此代碼之前運(yùn)行良好.我不確定這里出了什么問(wèn)題.你能指出我正確的方向嗎?謝謝!

                  解決方案

                  如浮點(diǎn)類(lèi)型(近似值) - FLOATDOUBLE:

                  <塊引用>

                  MySQL 在存儲(chǔ)值時(shí)執(zhí)行四舍五入,因此如果將 999.00009 插入到 FLOAT(7,4) 列中,近似結(jié)果為 999.0001>.

                  因?yàn)楦↑c(diǎn)值是近似值,而不是作為精確值存儲(chǔ),嘗試在比較中將它們視為精確值可能會(huì)導(dǎo)致問(wèn)題.它們還受制于平臺(tái)或?qū)崿F(xiàn)依賴(lài)性.有關(guān)詳細(xì)信息,請(qǐng)參閱第 C.5.5.8 節(jié),浮動(dòng)問(wèn)題 -點(diǎn)值"

                  為了獲得最大的可移植性,需要存儲(chǔ)近似數(shù)字?jǐn)?shù)據(jù)值的代碼應(yīng)使用 FLOATDOUBLE PRECISION,不指定精度或位數(shù).

                  因此,在將 1.8 插入您的數(shù)據(jù)庫(kù)后,MySQL 將文字四舍五入為 001.8000 并在 近似值 rel="nofollow">binary32 格式:即 0x3FE66666,其位表示:<前>簽名:0b0有偏指數(shù):0b01111111= 127(表示包括 +127 的偏差,因此 exp = 0)有效數(shù) : 0b[1.]11001100110011001100110^ 隱藏位,不以二進(jìn)制表示形式存儲(chǔ)= [1.]7999999523162841796875

                  這相當(dāng)于:

                  <前>(-1)^0 * 1.7999999523162841796875 * 2^0= 1.7999999523162841796875

                  這是 MySQL 返回給客戶(hù)端的值.看起來(lái) AdoDB 然后檢查了列的數(shù)據(jù)類(lèi)型并相應(yīng)地對(duì)結(jié)果進(jìn)行了四舍五入,而 PDO 則沒(méi)有.

                  如果你想要精確的值,你應(yīng)該使用固定點(diǎn)數(shù)據(jù)類(lèi)型,例如 DECIMAL.

                  I am guessing this has came up before, but I couldn't find the answer to my question. Here is a little code snippet:

                      $stmt = $this -> db -> query("
                          SELECT
                            `Field`
                          FROM
                            `Table`
                          WHERE
                            (`ID` = 33608)");
                      var_dump($stmt -> fetch());
                  

                  And this is the result I get:

                      array(1) { ["Field"]=> float(1.7999999523163) }
                  

                  However, the data in the MySQL database is 1.8. The type of the field is float(7,4). $this->db is a PDO object. I have recently migrated to PDO (from AdoDB), and this code was working fine before. I am not sure what went wrong here. Could you point me in the right direction? Thanks!

                  解決方案

                  As documented under Floating-Point Types (Approximate Value) - FLOAT, DOUBLE:

                  MySQL performs rounding when storing values, so if you insert 999.00009 into a FLOAT(7,4) column, the approximate result is 999.0001.

                  Because floating-point values are approximate and not stored as exact values, attempts to treat them as exact in comparisons may lead to problems. They are also subject to platform or implementation dependencies. For more information, see Section C.5.5.8, "Problems with Floating-Point Values"

                  For maximum portability, code requiring storage of approximate numeric data values should use FLOAT or DOUBLE PRECISION with no specification of precision or number of digits.

                  Therefore, upon inserting 1.8 into your database, MySQL rounded the literal to 001.8000 and encoded the closest approximation to that number in binary32 format: i.e. 0x3FE66666, whose bits signify:

                  Sign           : 0b0
                  
                  Biased exponent: 0b01111111
                                 =   127 (representation includes bias of +127, therefore exp = 0)
                  
                  Significand    : 0b[1.]11001100110011001100110
                                      ^ hidden bit, not stored in binary representation
                                 =   [1.]7999999523162841796875
                  

                  This equates to:

                   (-1)^0 * 1.7999999523162841796875 * 2^0
                  =         1.7999999523162841796875
                  

                  This is the value that is returned by MySQL to the client. It would appear that AdoDB then inspected the column's datatype and rounded the result accordingly, whereas PDO does not.

                  If you want exact values, you should use a fixed point datatype, such as DECIMAL.

                  這篇關(guān)于PHP PDO 查詢(xún)?yōu)?FLOAT 字段返回不準(zhǔn)確的值的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動(dòng)游標(biāo)不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術(shù)方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個(gè)值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動(dòng)程序)

                        <bdo id='ALUhJ'></bdo><ul id='ALUhJ'></ul>
                      • <i id='ALUhJ'><tr id='ALUhJ'><dt id='ALUhJ'><q id='ALUhJ'><span id='ALUhJ'><b id='ALUhJ'><form id='ALUhJ'><ins id='ALUhJ'></ins><ul id='ALUhJ'></ul><sub id='ALUhJ'></sub></form><legend id='ALUhJ'></legend><bdo id='ALUhJ'><pre id='ALUhJ'><center id='ALUhJ'></center></pre></bdo></b><th id='ALUhJ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ALUhJ'><tfoot id='ALUhJ'></tfoot><dl id='ALUhJ'><fieldset id='ALUhJ'></fieldset></dl></div>
                      • <small id='ALUhJ'></small><noframes id='ALUhJ'>

                        <tfoot id='ALUhJ'></tfoot>

                        • <legend id='ALUhJ'><style id='ALUhJ'><dir id='ALUhJ'><q id='ALUhJ'></q></dir></style></legend>

                            <tbody id='ALUhJ'></tbody>

                            主站蜘蛛池模板: 久久午夜视频 | 久久免费资源 | 国产精品视频网 | 久久成人高清视频 | 久久亚洲欧美日韩精品专区 | 亚洲一二三区精品 | 日韩欧美在线一区 | 国产精品96久久久久久 | 91精品国产综合久久精品 | 国产精品视频不卡 | 99国产精品久久久久 | 男女免费观看在线爽爽爽视频 | 中文字幕在线欧美 | 欧美 日韩 国产 成人 | 国产在线高清 | 婷婷综合色 | 日韩免费视频一区二区 | 色婷婷av久久久久久久 | 男人午夜视频 | 国产欧美精品一区二区三区 | 男女一区二区三区 | 精品国产乱码久久久久久丨区2区 | 草久久久 | 中文字幕在线免费观看 | 国产一区二区精品在线观看 | 亚洲精品久久久一区二区三区 | 久久精品亚洲精品 | 亚洲香蕉| 天堂在线一区 | 91久久久久久久 | 久久精品国产久精国产 | 二区欧美 | 夜夜精品视频 | 九九久久精品视频 | 美女久久视频 | 成人亚洲精品久久久久软件 | 中文字幕1区2区3区 亚洲国产成人精品女人久久久 | 涩涩片影院 | 成年人在线观看 | 欧美成年人视频在线观看 | 欧美一级大片免费看 |