MariaDB查询双数据类型
我正在尝试将查询(C++)数据类型(double)变量字符串化到mariaDB中。我正在成功地发送任何其他变量(I、b和buffer),但没有加倍 这里只是我试图发送变量hh和其他变量的代码的一部分。您可以看到我发送的任何其他变量都没有问题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)+","
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();