Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MariaDB查询双数据类型_Mariadb - Fatal编程技术网

MariaDB查询双数据类型

MariaDB查询双数据类型,mariadb,Mariadb,我正在尝试将查询(C++)数据类型(double)变量字符串化到mariaDB中。我正在成功地发送任何其他变量(I、b和buffer),但没有加倍 这里只是我试图发送变量hh和其他变量的代码的一部分。您可以看到我发送的任何其他变量都没有问题 double hh= -4.762486e-09; string query = "INSERT INTO tabulka (n, napatie, prud, cas) VALUES ("+to_string(i)+","+to_string(b)+","

我正在尝试将查询(C++)数据类型(double)变量字符串化到mariaDB中。我正在成功地发送任何其他变量(I、b和buffer),但没有加倍

这里只是我试图发送变量hh和其他变量的代码的一部分。您可以看到我发送的任何其他变量都没有问题

double hh= -4.762486e-09;
string query = "INSERT INTO tabulka (n, napatie, prud, cas) VALUES ("+to_string(i)+","+to_string(b)+","+to_string(hh)+",'"+buffer+"')";

在数据库tabulka中,我从变量hh接收到0

表tabulka:

MariaDB [hodnoty]> select n, napatie,prud, cas from hodnoty.tabulka;
+------+-----------+------+---------------------+
| n    | napatie   | prud | cas                 |
+------+-----------+------+---------------------+
|    1 |  0.000055 |    0 | 2020-03-03 12:20:09 |

当我尝试插入精确值时,可以:

MariaDB [hodnoty]> insert into tabulka (prud) values ('-4.7624816e-09');
Query OK, 1 row affected (0.001 sec)

你能帮我一下我做错了什么吗?将非常高兴。

您可以在执行查询字符串之前检查它

to_字符串(双精度)的精度为6位小数。要将double转换为string,请使用ostringstream

  std::ostringstream streamObj;
  streamObj << hh;
  cout << streamObj.str();
std::ostringstream streamObj;
streamObj将
打印到字符串(hh)
。我想这会告诉你问题所在。
MariaDB [hodnoty]> select n, napatie,prud, cas from hodnoty.tabulka;
+------+---------+---------------------+---------------------+
| n    | napatie | prud                | cas                 |
+------+---------+---------------------+---------------------+
| NULL |    NULL | -0.0000000047624816 | 2020-03-03 13:32:44 |
+------+---------+---------------------+---------------------+
  std::ostringstream streamObj;
  streamObj << hh;
  cout << streamObj.str();