{"id":13879673,"url":"https://github.com/piotrmurach/strings-numeral","last_synced_at":"2025-06-12T13:09:27.805Z","repository":{"id":59156665,"uuid":"228043585","full_name":"piotrmurach/strings-numeral","owner":"piotrmurach","description":"Express numbers as string numerals","archived":false,"fork":false,"pushed_at":"2021-10-24T14:19:39.000Z","size":122,"stargazers_count":20,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-18T02:51:21.614Z","etag":null,"topics":["cardinal","numeral","ordinal","rubygem","strings"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/piotrmurach.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"piotrmurach"}},"created_at":"2019-12-14T15:17:42.000Z","updated_at":"2023-02-05T10:21:01.000Z","dependencies_parsed_at":"2022-09-13T20:10:21.999Z","dependency_job_id":null,"html_url":"https://github.com/piotrmurach/strings-numeral","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/piotrmurach/strings-numeral","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fstrings-numeral","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fstrings-numeral/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fstrings-numeral/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fstrings-numeral/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/piotrmurach","download_url":"https://codeload.github.com/piotrmurach/strings-numeral/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fstrings-numeral/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259470951,"owners_count":22862999,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cardinal","numeral","ordinal","rubygem","strings"],"created_at":"2024-08-06T08:02:28.486Z","updated_at":"2025-06-12T13:09:27.775Z","avatar_url":"https://github.com/piotrmurach.png","language":"Ruby","funding_links":["https://github.com/sponsors/piotrmurach"],"categories":["Ruby"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"225\" src=\"https://github.com/piotrmurach/strings/blob/master/assets/strings_logo.png\" alt=\"strings logo\" /\u003e\n\u003c/div\u003e\n\n# Strings::Numeral\n\n[![Gem Version](https://badge.fury.io/rb/strings-numeral.svg)][gem]\n[![Actions CI](https://github.com/piotrmurach/strings-numeral/workflows/CI/badge.svg?branch=master)][gh_actions_ci]\n[![Build status](https://ci.appveyor.com/api/projects/status/494htkcankqegwtg?svg=true)][appveyor]\n[![Maintainability](https://api.codeclimate.com/v1/badges/de0c5ad1cba6715b7135/maintainability)][codeclimate]\n[![Coverage Status](https://coveralls.io/repos/github/piotrmurach/strings-numeral/badge.svg?branch=master)][coverage]\n[![Inline docs](https://inch-ci.org/github/piotrmurach/strings-numeral.svg?branch=master)][inchpages]\n\n[gem]: https://badge.fury.io/rb/strings-numeral\n[gh_actions_ci]: https://github.com/piotrmurach/strings-numeral/actions?query=workflow%3ACI\n[appveyor]: https://ci.appveyor.com/project/piotrmurach/strings-numeral\n[codeclimate]: https://codeclimate.com/github/piotrmurach/strings-numeral/maintainability\n[coverage]: https://coveralls.io/github/piotrmurach/strings-numeral?branch=master\n[inchpages]: https://inch-ci.org/github/piotrmurach/strings-numeral\n\n\u003e Express numbers as string numerals.\n\n**Strings::Numeral** provides conversions of numbers to numerals component for [Strings](https://github.com/piotrmurach/strings).\n\n## Features\n\n* No monkey-patching String class\n* Functional API that can be easily wrapped by other objects\n* Instance based configuration\n* Highly performant\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'strings-numeral'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install strings-numeral\n\n## Contents\n\n* [1. Usage](#1-usage)\n* [2. API](#2-api)\n  * [2.1 numeralize](#21-numeralize)\n  * [2.2 cardinalize](#22-cardinalize)\n  * [2.3 ordinalize](#23-ordinalize)\n  * [2.4 monetize](#24-monetize)\n  * [2.5 romanize](#25-romanize)\n  * [2.6 configuration](#26-configuration)\n* [3. Extending core classes](#3-extending-core-classes)\n\n## 1. Usage\n\n**Strings::Numeral** helps to express any number as a numeral in words. It exposes few methods to achieve this. For example, you can express a number as a cardinal numeral using `cardinalize`:\n\n```ruby\nStrings::Numeral.cardinalize(1234)\n# =\u003e \"one thousand, two hundred thirty four\"\n```\n\nBut you're not limited to converting integers only. It can handle decimals as well:\n\n```ruby\nStrings::Numeral.cardinalize(1234.567)\n# =\u003e \"one thousand, two hundred thirty four and five hundred sixty seven thousandths\"\n```\n\nFor more options on how to customize formatting see [configuration](#25-configuration) section.\n\nSimilarly, you can convert a number to a ordinal numeral with `ordinalize`:\n\n```ruby\nStrings::Numeral.ordinalize(1234)\n# =\u003e \"one thousand, two hundred thirty fourth\"\n```\n\nYou can also convert a number to a short ordinal:\n\n```ruby\nStrings::Numeral.ordinalize(1234, short: true)\n# =\u003e \"1234th\"\n```\n\nUsing `monetize` you can convert any number into a monetary numeral:\n\n```ruby\nStrings::Numeral.monetize(1234.567)\n# =\u003e \"one thousand, two hundred thirty four dollars and fifty seven cents\",\n```\n\nTo turn a number into a roman numeral use `romanize`:\n\n```ruby\nStrings::Numeral.romanize(2020)\n# =\u003e \"MMXX\"\n```\n\n## 2. API\n\n### 2.1 numeralize\n\nThe `normalize` is a wrapping method for the [cardinalize](#22-cardinalize) and [ordinalize](#23-ordinalize) methods. By default it converts a number to cardinal numeral:\n\n```ruby\nStrings::Numeral.numeralize(1234.567)\n# =\u003e \"one thousand, two hundred thirty four and five hundred sixty seven thousandths\"\n```\n\nYou can also make it convert to ordinal numerals using `:term` option:\n\n```ruby\nStrings::Numeral.numeralize(1234.567, term: :ord)\n# =\u003e \"one thousand, two hundred thirty fourth and five hundred sixty seven thousandths\"\n```\n\n### 2.2 cardinalize\n\nTo express a number as a cardinal numeral use `cardinalize` or `cardinalise`.\n\n```ruby\nStrings::Numeral.cardinalize(1234)\n# =\u003e \"one thousand, two hundred thirty four\"\n```\n\nYou're not limited to integers only. You can also express decimal numbers as well:\n\n```ruby\nStrings::Numeral.cardinalize(123.456)\n# =\u003e \"one hundred twenty three and four hundred fifty six thousandths\"\n```\n\nBy default the fractional part of a decimal number is expressed as a fraction. If you wish to spell out fractional part digit by digit use `:decimal` option with `:digit` value:\n\n```ruby\nStrings::Numeral.cardinalize(123.456, decimal: :digit)\n# =\u003e \"one hundred twenty three point four five six\"\n```\n\nYou may prefer to use a different delimiter for thousand's. You can do use by passing the `:delimiter` option:\n\n```ruby\nStrings::Numeral.cardinalize(1_234_567, delimiter: \" and \")\n# =\u003e \"one million and two hundred thirty four thousand and five hundred sixty seven\"\n```\n\nTo change word that splits integer from factional part use `:separator` option:\n\n```ruby\nStrings::Numeral.cardinalize(1_234.567, separator: \"dot\")\n# =\u003e \"one thousand, two hundred thirty four dot five hundred sixty seven thousandths\"\n```\n\n### 2.3 ordinalize\n\nTo express a number as a cardinal numeral use `ordinalize` or `ordinalise`.\n\n```ruby\nStrings::Numeral.ordinalize(1234)\n# =\u003e \"one thousand, two hundred thirty fourth\"\n```\n\nYou're not limited to integers only. You can also express decimal numbers as well:\n\n```ruby\nStrings::Numeral.ordinalize(123.456)\n# =\u003e \"one hundred twenty third and four hundred fifty six thousandths\"\n```\n\nBy default the fractional part of a decimal number is expressed as a fraction. If you wish to spell out fractional part digit by digit use `:decimal` option with `:digit` value:\n\n```ruby\nStrings::Numeral.ordinalize(123.456, decimal: :digit)\n# =\u003e \"one hundred twenty third point four five six\"\n```\n\nYou may prefer to use a different delimiter for thousand's. You can do use by passing the `:delimiter` option:\n\n```ruby\nStrings::Numeral.ordinalize(1_234_567, delimiter: \" and \")\n# =\u003e \"one million and two hundred thirty four thousand and five hundred sixty seventh\"\n```\n\nTo change word that splits integer from factional part use `:separator` option:\n\n```ruby\nStrings::Numeral.ordinalize(1_234.567, separator: \"dot\")\n# =\u003e \"one thousand, two hundred thirty fourth dot five hundred sixty seven thousandths\"\n```\n\n### 2.4 monetize\n\nTo express a number as a monetary numeral use `monetize` or `monetise`.\n\n```ruby\nStrings::Numeral.monetize(123.456)\n# =\u003e \"one hundred twenty three dollars and forty six cents\",\n```\n\nBy default `monetize` displays money using `USD` currency. You can change this with the `:currency` option that as value accepts internationally recognised symbols. Currently support currencies are: `EUR`, `GBP`, `JPY`, `PLN` and `USD`.\n\n```ruby\nStrings::Numeral.monetize(123.456, currency: :jpy)\n# =\u003e \"one hundred twenty three yen and forty six sen\"\n```\n\n### 2.5 romanize\n\nTo convert a number into a Roman numeral use `romanize`:\n\n```ruby\nStrings::Numeral.romanize(2020)\n# =\u003e \"MMXX\"\n```\n\n### 2.6 configuration\n\nAll available configuration settings are:\n\n* `currency` - Adds currency words for integer and fractional parts. Supports `EUR`, `GBP`, `JPY`, `PLN` and `USD`. Defaults to `USD`.\n* `decimal` - Formats fractional part of a number. The `:digit` value spells out every digit and the `:fraction` appends divider word. Defaults to `:fraction`.\n* `delimiter` - Sets the thousands delimiter. Defaults to `\", \"`.\n* `separator` - Sets the separator between the fractional and integer parts. Defaults to `\"and\"` for `:fraction` and `\"point\"` for `:digit` option.\n* `strict` - Enables number validation for the input parameter. Defaults to `false`.\n* `trailing_zeros` - If `true` keeps trailing zeros at the end of the fractional part. Defaults to `false`.\n\nThe above settings can be passed as keyword arguments:\n\n```ruby\nStrings::Numeral.cardinalize(\"12.100\", trailing_zeros: true, decimal: :digit)\n# =\u003e \"twelve point one zero zero\"\n```\n\nOr you can configure the settings for an instance during initialisation:\n\n```ruby\nnumeral = Strings::Numeral.new(delimiter: \"; \", separator: \"dot\")\n```\n\nAfter initialisation, you can use `configure` to change settings inside a block:\n\n```ruby\nnumeral.configure do |config|\n  config.delimiter \"; \"\n  config.separator \"dot\"\n  config.decimal :digit\n  config.trailing_zeros true\nend\n```\n\nOnce configured, you can use the instance like so:\n\n```ruby\nnumeral.cardinalize(\"1234.56700\")\n# =\u003e \"one thousand; two hundred thirty four dot five six seven zero zero\"\n```\n\n## 3. Extending Core Classes\n\nThough it is highly discouraged to pollute core Ruby classes, you can add the required methods to `String`, `Float` and `Integer` classes using refinements.\n\nFor example, if you wish to only extend `Float` class with `cardinalize` method do:\n\n```ruby\nmodule MyFloatExt\n  refine Float do\n    def cardinalize(**options)\n      Strings::Numeral.cardinalize(self, **options)\n    end\n  end\nend\n```\n\nThen `cardinalize` method will be available for any float number where refinement is applied:\n\n```ruby\nusing MyFloatExt\n\n12.34.cardinalize\n# =\u003e \"twelve and thirty four\"\n```\n\nHowever, if you want to include all the **Strings::Numeral** methods in `Float`, `Integer` and `String` classes, you can use provided extensions file:\n\n\n```ruby\nrequire \"strings/numeral/extensions\"\n\nusing Strings::Numeral::Extensions\n```\n\nAlternatively, you can choose what class you wish to refine with all the methods:\n\n```ruby\nrequire \"bigdecimal\"\nrequire \"strings/numeral/extensions\"\n\nmodule MyBigDecimalExt\n  refine BigDecimal do\n    include Strings::Numeral::Extensions::Methods\n  end\nend\n\nusing MyBigDecimalExt\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/piotrmurach/strings-numeral. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/piotrmurach/strings-numeral/blob/master/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Strings::Numeral project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/piotrmurach/strings-numeral/blob/master/CODE_OF_CONDUCT.md).\n\n## Copyright\n\nCopyright (c) 2019 Piotr Murach. See LICENSE for further details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiotrmurach%2Fstrings-numeral","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpiotrmurach%2Fstrings-numeral","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiotrmurach%2Fstrings-numeral/lists"}