Skip to content

Have numbers formatted with suffixes like K, M, B, T #134

Closed

Description

@jkfding

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

1.00, 1.00K, 2.43M, 234.20M, 20.34T

Activity

  1. rich-iannone commented on Jan 15, 2019

    @rich-iannone
    Member

    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"
    
  2. self-assigned this
    on Jan 15, 2019
  3. rich-iannone commented on Jan 16, 2019

    @rich-iannone
    Member

    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.

  4. r-cheologist commented on Jan 16, 2019

    @r-cheologist

    I commented here, but PLEASE also implement easy scientific notation, e.g. 1500000 --> "1.5 <× OR · e.g.> 10^6^.

  5. rich-iannone commented on Jan 16, 2019

    @rich-iannone
    Member
  6. r-cheologist commented on Jan 16, 2019

    @r-cheologist

    Ouch. Sorry for the noise.

  7. rich-iannone commented on Jan 16, 2019

    @rich-iannone
    Member

    @r-cheologist it's okay!

  8. jkfding commented on Feb 3, 2019

    @jkfding
    Author

    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!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions