Skip to content

Printing double with custom precision outputs wrong format #58

@scakko84

Description

@scakko84

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}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions