Skip to content

Precision problem of cJSON_AddNumberToObject(); with double and float. #41

Description

@ironengineer

Question:
How can I add the double value only with given precision as provided 100.2 instead of 100.200000. Is it possible to generate the expected result below?

(When I gave the same number as float number = 100.2;, it generates: {"number value":100.199997} )
Example code:

double number = 100.2;
cJSON_AddNumberToObject(json, "number value", number);

Expected result:
{"number value":100.2}

Generated result:
{"number value":100.200000}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions