Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
H

humanize

> 编程语言
Open source

Takes your numbers and makes them *fancy*.

473 stars0 likes3 views
WebsiteGitHub

About

Takes your numbers and makes them *fancy*.

Humanize

Converts numbers to strings.

ruby
2.humanize  # => "two"
4.humanize  # => "four"
8.humanize  # => "eight"
15.humanize # => "fifteen"
16.humanize # => "sixteen"
23.humanize # => "twenty three"
42.humanize # => "forty two"

All the way up to 156 digit numbers:

…

If you are dealing with numbers larger than 156 digits, we accept patches. Word list is sourced from: [ Wordlist.source ]

Usage (Extends Ruby Core)

Note: this extends to Ruby core classes Integer, Float, and BigDecimal. See below for usage without extending Ruby core.

Install the gem using RubyGems

bash
gem install humanize

or:

Add it to your Gemfile

ruby
gem 'humanize'

Include it in your program

ruby
require 'humanize'

Call the method on the numbers

ruby
100.humanize => "one hundred"
1001.humanize => "one thousand and one"
0.001.humanize => "zero point zero zero one"

Usage (Without Extending Ruby Core)

Note: this usage does not extend Ruby core. Instead it relies on explicitly calling the pure function Humanize.format.

Install the gem using RubyGems

bash
gem install humanize

or:

Add it to your Gemfile

ruby
gem 'humanize', require: false

Include the module in your program

ruby
require 'humanize/module' # does not extend Ruby corex

Call the format function on the numbers

ruby
Humanize.format(100) => "one hundred"
Humanize.format(1001) => "one thousand and one"
Humanize.format(0.001) => "zero point zero zero one"

Configuration

ruby
Humanize.configure do |config|
  config.locale = :en  # [:en, :es, :fr, :'fr-CH', :tr, :az, :de, :id, :th, :ru, :pt, :ms, :jp, :vi, :'zh-tw', :ar], default: :en
  config.decimals_as = :digits # [:digits, :number], default: :digits
end

The default locale can be overridden by passing an explicit locale::

ruby
42.humanize(locale: :fr) # => "quarante-deux"
1666.humanize(locale: :tr) # => "bin altı yüz altmış altı"

Or, functionally:

ruby
Humanize.format(42, locale: :fr) # => "quarante-deux"
Humanize.format(1666, locale: :tr) # => "bin altı yüz altmış altı"

Decimals

Similarly, the default display of decimals can be overridden by passing an explicit decimals_as: value:

ruby
0.42.humanize(decimals_as: :digits) # => "zero point four two"
0.42.humanize(decimals_as: :number) # => "zero point forty-two"

Or, functionally:

ruby
Humanize.format(0.42, decimals_as: :digits) # => "zero point four two"
Humanize.format(0.42, decimals_as: :number) # => "zero point forty-two"

I18n

Currently supported locales:

  • English: :en
  • Spanish: :es
  • French: :fr
  • Swiss French: :'fr-CH'
  • Turkish: :tr
  • Azerbaijani :az
  • German: :de
  • Indonesian: :id
  • Thai: :th
  • Russian: :ru (except for decimals)
  • Portuguese: :pt
  • Malaysia :ms
  • Japanese :jp
  • Vietnamese :vi
  • Traditional Chinese :zh-tw
  • Arabic :ar

Testing

Install development dependencies by running bundle install.

You can run mutation testing by calling bin/run_mutant.

Credits

  • Original idea: Brenton Fletcher
  • Unbastardisation of original idea: Ryan Bigg
  • Awesome speed up: Jack "Chendo" Chen

Issues· 8 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言