Skip to content

Insert float casted to double add noise to field #210

@Globostofo

Description

@Globostofo

My goal is to insert my float variable in the database.
But when I call the addField method and cast the float into double, the variable gets a weird noise (little supplement) at the end:

This code:

float value = 3.141592f
influxdb::Point p1{"cpu"};
p1.addField("value", (double) value);
std::cout << p1.getFields() << std::endl;

displays this output:

value=3.141592025756835938

As you can see, a few digits are added at the end of the value, not far from the last digit.

I also tried casting with static_cast<double>(value) but it didn't work (same if I pass the float as is, without casting).

Edit:
To sum up, I'd like to know if it's possible to have as much precision as if I inserted a double:

value=3.141592000000000162

NB: with such a value, InfluxDB ignores the 162 at the end, and give me the tuple when I do a query with WHERE value=3.141592 (which is not the case with the float result).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions