Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

16-digit integers ending with 0 are printed in exponential format #758

Open
Hironobu-Ishii opened this issue May 9, 2023 · 0 comments · May be fixed by #759
Open

16-digit integers ending with 0 are printed in exponential format #758

Hironobu-Ishii opened this issue May 9, 2023 · 0 comments · May be fixed by #759

Comments

@Hironobu-Ishii
Copy link

16-digit integers ending with 0 are printed in exponential format. Non-zero ending cases are printed as expected.

Output from the sample code

cJSON Version: 1.7.15
{
	"OK1":	1234567890123456,
	"OK2":	1234567890123457,
	"OK3":	1234567890123458,
	"OK4":	1234567890123459,
	"NG1":	1.23456789012346e+15,
	"OK5":	1234567890123461,
	"OK6":	1234567890123462,
	"OK7":	1234567890123463,
	"OK8":	1234567890123464,
	"OK9":	1234567890123465,
	"NG2":	1.23456789012347e+15,
	"OK10":	1234567890123471
}

Sample code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cJSON.h"

static void create_objects(void)
{
    /* declare a few. */
    cJSON *root = NULL;
    char *out;

    root = cJSON_CreateObject();

    cJSON_AddNumberToObject(root, "OK1", 1234567890123456);
    cJSON_AddNumberToObject(root, "OK2", 1234567890123457);
    cJSON_AddNumberToObject(root, "OK3", 1234567890123458);
    cJSON_AddNumberToObject(root, "OK4", 1234567890123459);
    cJSON_AddNumberToObject(root, "NG1", 1234567890123460);
    cJSON_AddNumberToObject(root, "OK5", 1234567890123461);
    cJSON_AddNumberToObject(root, "OK6", 1234567890123462);
    cJSON_AddNumberToObject(root, "OK7", 1234567890123463);
    cJSON_AddNumberToObject(root, "OK8", 1234567890123464);
    cJSON_AddNumberToObject(root, "OK9", 1234567890123465);
    cJSON_AddNumberToObject(root, "NG2", 1234567890123470);
    cJSON_AddNumberToObject(root, "OK10", 1234567890123471);

    /* Print to text */
    if ((out = cJSON_Print(root)) == 0) {
        cJSON_Delete(root);
        exit(EXIT_FAILURE);
    }
    printf("%s\n", out);
    cJSON_Delete(root);
    return;
}

int main(void)
{
    /* print the version */
    printf("cJSON Version: %s\n", cJSON_Version());

    /* Now some samplecode for building objects concisely: */
    create_objects();

    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant