Skip to content

Commit 92b08d9

Browse files
authored
Merge pull request rstudio#1962 from olivroy/use-seps
Add workaround for removing the trailing dec mark when sep_mark = ""
2 parents 37a25ab + 84095e1 commit 92b08d9

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# gt (development version)
22

3+
* Fixed an issue in `fmt_number()` where `drop_trailing_dec_mark` would be ignored if `use_seps = FALSE` (@olivroy, #1961).
4+
35
* Fixed an issue where `fmt_markdown()` could create strange output in Quarto (html and Typst formats) (@olivroy, #1957, [quarto-dev/quarto-cli#11932](https://github.com/quarto-dev/quarto-cli/issues/11932), [quarto-dev/quarto-cli#11610](https://github.com/quarto-dev/quarto-cli/issues/11610)).
46

57
* The default table position in LaTeX is now "t" instead of "!t" (@AaronGullickson, #1935).

R/fmt.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,10 @@ format_num_to_str <- function(
610610
if (!drop_trailing_dec_mark) {
611611
x_str_no_dec <- !grepl(dec_mark, x_str, fixed = TRUE)
612612
x_str[x_str_no_dec] <- paste_right(x_str[x_str_no_dec], dec_mark)
613+
} else if (nzchar(dec_mark) && !nzchar(sep_mark)) {
614+
# drop the trailing dec mark if sep mark is the empty ""
615+
# needed in some cases https://github.com/rstudio/gt/issues/1961
616+
x_str[endsWith(x_str, dec_mark)] <- sub(dec_mark, "", x_str[endsWith(x_str, dec_mark)], fixed = TRUE)
613617
}
614618

615619
# Perform modifications to `x_str` values if formatting values to

tests/testthat/test-fmt_number.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,3 +1092,10 @@ test_that("fmt_number() can render values in the Indian numbering system", {
10921092
render_formats_test(expected_tab, context = "html")[["num"]]
10931093
)
10941094
})
1095+
1096+
test_that("fmt_number() works with n_sigfig, drop_trailing_dec_mark = TRUE (#1961)", {
1097+
expect_equal(
1098+
format_num_to_str(1335.3, "html", n_sigfig = 4, sep_mark = "", dec_mark = ".", drop_trailing_dec_mark = T,format = "fg"),
1099+
"1335"
1100+
)
1101+
})

0 commit comments

Comments
 (0)