I am using libpq
to connect to Postgres on Windows 10 using Visual Studio 2015, PostgreSQL9.4
I have a table like this:
CREATE TABLE real_data (
plane_id integer NOT NULL PRIMARY KEY,
timestamp integer NOT NULL,
data1 double precision
);
INSERT INTO real_data VALUES ('100001', '14987654', 635.28938)
And when I get it out char* data1 = PQgetvalue(res, row,2);
, data1
is "635.28938"
in the watch, and if I convert it to double with atof
, double d_value = atof(data1)
, d_value
is 635.28938000000000005
. It's not exactly the same.
I found this question on SO: How to get the double value using libpq? , but I don't think I can follow it since I have a ascii string representing the original double in data1
.
How can I get an accurate double number from Postgres?
Thanks a lot.