Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

number_to_human helper method #1300

Open
jwoertink opened this issue Nov 6, 2020 · 1 comment
Open

number_to_human helper method #1300

jwoertink opened this issue Nov 6, 2020 · 1 comment
Labels
feature request A new requested feature / option

Comments

@jwoertink
Copy link
Member

jwoertink commented Nov 6, 2020

In rails, I have this method

format = number_only ? "%n%u" : "%n%u #{thing.pluralize(number)}"

    number_to_human(
      number,
      format: format,
      precision: 2,
      units: {
        thousand: 'k',
        million: 'm'
      }
    )

Which allows me to output something like "1.5k Users". The closest we have right now is something like:

text count.humanize
text pluralize(count, "User")

which would output "1.5k 1500 Users". It would be nice to have this helper method added in.

@jwoertink jwoertink added the feature request A new requested feature / option label Nov 6, 2020
@jwoertink
Copy link
Member Author

After a little thought, the humanize method built in to crystal already does most of this. We can also just use wordsmith to pluralize the word without the count... So really this may not even be needed. Maybe just some examples floating around 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A new requested feature / option
Projects
None yet
Development

No branches or pull requests

1 participant