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

Printing double with custom precision outputs wrong format #58

Open
scakko84 opened this issue Mar 6, 2023 · 1 comment
Open

Printing double with custom precision outputs wrong format #58

scakko84 opened this issue Mar 6, 2023 · 1 comment

Comments

@scakko84
Copy link

scakko84 commented Mar 6, 2023

The precision argument while printing a double with given precision seems to be treated as width instead.

Documentation

%.*g, print floating point number with given precision. Expect int, double

Test 1

int num_precision = 10;
double num = 123.1234567891;
char *s = mjson_aprintf("{%Q:%.*g}", "num", num_precision, num);
printf("%s\n", s);
free(s);
// output: {"num":123.1234568}

Test 2

int num_precision = 13;
double num = 123.1234567891;
char *s = mjson_aprintf("{%Q:%.*g}", "num", num_precision, num);
printf("%s\n", s);
free(s);
// output: {"num":123.1234567891}
@d4rkmen
Copy link

d4rkmen commented Apr 19, 2023

Generally, the %.*g is a length formater, the precission is %.2g, but seems its not implemented

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

No branches or pull requests

2 participants