langcog / wordbank-book

https://langcog.github.io/wordbank-book/
16 stars 5 forks source link

consistentify printing of numbers #82

Closed mikabr closed 4 years ago

mikabr commented 5 years ago

right now some are in within latex math mode and some are in plain text

mcfrank commented 4 years ago

also we use round as our function for rounding but it has terrible properties.

how's this for a bad piece of code to replace it:

Round <- function (x, digits = 1) {
  if (digits == 1) {
    sprintf("%.1f", round(x, digits = 1))
  } else if (digits == 2) {
    sprintf("%.2f", round(x, digits = 2))
  }
}

I'm sure by putting this awful if statement in front of you it will induce you to fix it @mikabr ?

mcfrank commented 4 years ago

in general our problem is that we want significant digits but we want the final zeros printed too.

note that chapter 8 has its own digits settings in its preamble, that's one approach we could use?

mikabr commented 4 years ago

I've change number printing pretty much everywhere to be:

roundp <- function(x, digits = 2) {
  sprintf(glue('%.{digits}f'), round(x, digits)) %>% str_replace("-", "–")
}

we can make adjustments to it centrally!