You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Have numbers formatted with suffixes like K, M, B, T #134
Really, really love this package! It is amazing. :)
What would make it even better is having an option (maybe in fmt_number) to automatically add endings to numbers like K (thousands), M (millions), B (billions), and T (trillions) for large numbers.
Example:
the numbers 1, 1000, 2432000, 234202034, 20340000000000 get formatted as
This is a great idea, and something we thought about awhile back. In reading up about this, I think that the sequence is generally: k or K or M (thousands, not always used), M or MM (millions), B (billions), and less commonly T (trillions).
Since these are so various, we could have the user choose (but have defaults of c("K", "M", "B", "T")) by specifying a character vector of four elements for the symbols. If we don't want to use K for instance, and start this formatting at M, we can put in an NA (c(NA, "M", "B", "T")). A single argument in fmt_number() (suffixing) could handle this. The default for suffixing would be FALSE (no application of scaling and adding number suffixes). Using TRUE would put in the default set as mentioned above. Here are some examples with a column containing 1, 1000, 20E+6, 25E+9, 30E+12:
# case where suffixing is set to TRUE
data %>%
fmt_number(
decimals = 2,
suffixing = TRUE)
-> "1.00", "1.00K", "20.00M", "25.00B", "30.00T"
# case where suffixing is set to c(NA, "Mio", "Bn", "T")
data %>%
fmt_number(
decimals = 2,
suffixing = c(NA, "Mio", "Bn", "T"))
-> "1.00", "1000.00", "20.00Mio", "25.00Bn", "30.00T"
Just thinking about this a bit more and it seems kinda reasonable to have this work in fmt_currency() as well. Don't know why I didn't think of that earlier, but I thought of it just now, and that's what really matters.
I tried out the new feature. Works wonderfully! Thanks so much.
BTW new r user here and even though I've got little experience with it, packages like gt make it so easy for the beginner. People here at work like the package a lot. There's nothing else quite like this package, it's just so useful. THANKS!!
Activity
rich-iannone commentedon Jan 15, 2019
This is a great idea, and something we thought about awhile back. In reading up about this, I think that the sequence is generally: k or K or M (thousands, not always used), M or MM (millions), B (billions), and less commonly T (trillions).
Since these are so various, we could have the user choose (but have defaults of
c("K", "M", "B", "T")) by specifying a character vector of four elements for the symbols. If we don't want to useKfor instance, and start this formatting atM, we can put in an NA (c(NA, "M", "B", "T")). A single argument infmt_number()(suffixing) could handle this. The default forsuffixingwould beFALSE(no application of scaling and adding number suffixes). UsingTRUEwould put in the default set as mentioned above. Here are some examples with a column containing1,1000,20E+6,25E+9,30E+12:rich-iannone commentedon Jan 16, 2019
Just thinking about this a bit more and it seems kinda reasonable to have this work in
fmt_currency()as well. Don't know why I didn't think of that earlier, but I thought of it just now, and that's what really matters.r-cheologist commentedon Jan 16, 2019
I commented here, but PLEASE also implement easy scientific notation, e.g.
1500000--> "1.5 <× OR · e.g.> 10^6^.rich-iannone commentedon Jan 16, 2019
@r-cheologist scientific notation formatting is already implemented in
fmt_scientific()(https://gt.rstudio.com/reference/fmt_scientific.html).r-cheologist commentedon Jan 16, 2019
Ouch. Sorry for the noise.
rich-iannone commentedon Jan 16, 2019
@r-cheologist it's okay!
jkfding commentedon Feb 3, 2019
I tried out the new feature. Works wonderfully! Thanks so much.
BTW new r user here and even though I've got little experience with it, packages like gt make it so easy for the beginner. People here at work like the package a lot. There's nothing else quite like this package, it's just so useful. THANKS!!