Skip to content

Commit

Permalink
digits = NA once again prints 15 digits max
Browse files Browse the repository at this point in the history
This partially reverts #412
Fixes #420
  • Loading branch information
jeroen committed Jun 27, 2023
1 parent 41ffee7 commit 120cca8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: jsonlite
Version: 1.8.6
Version: 1.8.7
Title: A Simple and Robust JSON Parser and Generator for R
License: MIT + file LICENSE
Depends: methods
Expand Down
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1.8.7
- toJSON(digits = NA) once again prints 15 digits max

1.8.6
- Add method [.json such that subsetting keeps json class

Expand Down
2 changes: 1 addition & 1 deletion src/num_to_char.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ SEXP R_num_to_char(SEXP x, SEXP digits, SEXP na_as_string, SEXP use_signif, SEXP
}
} else {
if(precision == NA_INTEGER){
snprintf(buf, 32, "%.17g", val);
snprintf(buf, 32, "%.15g", val);
} else if(signif){
//use signifant digits rather than decimal digits
snprintf(buf, 32, "%.*g", sig_digits, val);
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-toJSON-numeric.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test_that("Encoding Numbers", {
expect_that(toJSON(c(pi, NA), na="null", digits=5), equals("[3.14159,null]"));
expect_that(toJSON(c(pi, NA), na="null", digits=5), equals("[3.14159,null]"));
expect_that(toJSON(c(1478002353.51369, -521997646.486311) * 1000, digits = 0), equals("[1478002353514,-521997646486]"));
expect_that(toJSON(list(a=c(0.1)), digits = NA), equals('{"a":[0.1]}'));
});

test_that("Encoding Numbers in Data Frame", {
Expand Down

0 comments on commit 120cca8

Please sign in to comment.