Skip to content

Number decimal point - #1046

Open
chmorgan wants to merge 5 commits into
DaveGamble:masterfrom
chmorgan:number_decimal_point
Open

Number decimal point#1046
chmorgan wants to merge 5 commits into
DaveGamble:masterfrom
chmorgan:number_decimal_point

Conversation

@chmorgan

@chmorgan chmorgan commented Jul 3, 2026

Copy link
Copy Markdown

This is #558 rebased against the latest master.

Changes from original PR:

  • Added tests to confirm the decimal place is honored when print formatting.
  • Fixed a dereference of NULL pointer that can occur if the number allocation fails.

@chmorgan
chmorgan force-pushed the number_decimal_point branch 2 times, most recently from a525811 to d8a62e5 Compare July 3, 2026 12:11
@GitMensch

Copy link
Copy Markdown
Contributor

looks reasonable - just wondering if this new function should be included in the README, most likely in the Changelog

@chmorgan

chmorgan commented Aug 1, 2026

Copy link
Copy Markdown
Author

@GitMensch it might stand out if it were in the README.md, only a few of the cJSON_Addxxx variants are mentioned in the docs although the examples in the README.md do show them. Thoughts on where it should go in the README, if you still think it should go there?

@GitMensch

Copy link
Copy Markdown
Contributor

in the printing example - but I've also recognized that the approach may be "the header is the documentation" (there aren't even much comments on CJSON_PUBLIC marked functions)... and otherwise the Changelog, which seems to be redacted by @Alanscut

ajaybhargav and others added 4 commits August 1, 2026 13:49
Add cJSON_AddNumberWithPrecisionToObject so non-integral values can be printed with a requested number of digits after the decimal point. Integral values retain normal JSON formatting without a decimal point or trailing zeroes.

Signed-off-by: Ajay Bhargav <contact@rickeyworld.info>
Signed-off-by: Ajay Bhargav <contact@rickeyworld.info>
Signed-off-by: Ajay Bhargav <contact@rickeyworld.info>
Add public API regressions for cJSON_AddNumberWithPrecisionToObject formatting through cJSON_PrintUnformatted.

The cases assert requested decimal-place formatting for fractional values, printf-style rounding, negative number formatting, preservation of ordinary integer formatting without a decimal point or trailing zeroes, and the accepted maximum precision boundary.

Also cover invalid precision bounds by checking that 0 and 15 are rejected and leave the destination object empty.
@chmorgan
chmorgan force-pushed the number_decimal_point branch from 105ac8f to 85b54b8 Compare August 1, 2026 18:50
Document rounding a high-precision fractional value and unchanged integral formatting, including the generated JSON. Mirror the example in readme_examples so the documented behavior remains executable.
@chmorgan
chmorgan force-pushed the number_decimal_point branch from 85b54b8 to 96759d8 Compare August 1, 2026 22:40
@chmorgan

chmorgan commented Aug 1, 2026

Copy link
Copy Markdown
Author

@GitMensch example pushed

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 this pull request may close these issues.

3 participants