Home  >  Article  >  Backend Development  >  php-sqllite - php将二进制双精度浮点数据存到SQLlite3里面,结果居然不正确,怎么回事?

php-sqllite - php将二进制双精度浮点数据存到SQLlite3里面,结果居然不正确,怎么回事?

WBOY
WBOYOriginal
2016-06-06 20:08:32902browse

1.近日在做一些sqlite3方面的事情,定义了一个blob类型的字段,想把双精度浮点数存到这里面,于是诡异的事情发生了。双精度浮点数13.46,十六进制为402A EB85 1EB8 51EC,可是SQLITE里面的数据是 402A CB85 1EC2 B851 EFBF BD,这TM什么鬼,代码如下:

<code>$str=$common->DoubleToHex(13.46);
$s=hex2bin($str);
echo $str;//输出的结果是402A EB85 1EB8 51EC,这是正确的
$data->InsertData("table01", "'SS','0','".$s."'","time,timespan,data");//把数据插入到sqlite里面,数据就不对了
</code>

奇怪的是,错误只在double的时候产生,其他数据格式都没问题。

回复内容:

1.近日在做一些sqlite3方面的事情,定义了一个blob类型的字段,想把双精度浮点数存到这里面,于是诡异的事情发生了。双精度浮点数13.46,十六进制为402A EB85 1EB8 51EC,可是SQLITE里面的数据是 402A CB85 1EC2 B851 EFBF BD,这TM什么鬼,代码如下:

<code>$str=$common->DoubleToHex(13.46);
$s=hex2bin($str);
echo $str;//输出的结果是402A EB85 1EB8 51EC,这是正确的
$data->InsertData("table01", "'SS','0','".$s."'","time,timespan,data");//把数据插入到sqlite里面,数据就不对了
</code>

奇怪的是,错误只在double的时候产生,其他数据格式都没问题。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn