https://github.com/janlelis/unicode-numeric_value
Convert a Unicode character into its numeric value
https://github.com/janlelis/unicode-numeric_value
numbers numeric ruby unicode unicode-data value
Last synced: 3 months ago
JSON representation
Convert a Unicode character into its numeric value
- Host: GitHub
- URL: https://github.com/janlelis/unicode-numeric_value
- Owner: janlelis
- License: mit
- Created: 2016-04-16T09:14:36.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2025-09-09T15:17:10.000Z (4 months ago)
- Last Synced: 2025-09-21T21:23:21.589Z (4 months ago)
- Topics: numbers, numeric, ruby, unicode, unicode-data, value
- Language: Ruby
- Homepage: https://character.construction/numbers
- Size: 145 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: MIT-LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Unicode::NumericValue [![[version]](https://badge.fury.io/rb/unicode-numeric_value.svg)](https://badge.fury.io/rb/unicode-numeric_value) [![[ci]](https://github.com/janlelis/unicode-numeric_value/workflows/Test/badge.svg)](https://github.com/janlelis/unicode-numeric_value/actions?query=workflow%3ATest)
Convert a Unicode character into its numeric value.
Unicode version: **17.0.0** (September 2025)
## Gemfile
```ruby
gem "unicode-numeric_value"
```
## Usage
Can return Integer, Rational or nil:
```ruby
require "unicode/numeric_value"
Unicode::NumericValue.of("1") # => 1
Unicode::NumericValue.of("Ⅷ") # => 8
Unicode::NumericValue.of("⓳") # => 19
Unicode::NumericValue.of("¾") # => (3/4)
Unicode::NumericValue.of("༳") # => (-1/2)
Unicode::NumericValue.of("𑿀") # => (1/320)
Unicode::NumericValue.of("𖭡") # => 1000000000000
Unicode::NumericValue.of("五") # => 5
Unicode::NumericValue.of("") # => 7
Unicode::NumericValue.of("A") # => nil
```
## All Numeric Values
See a list of all numbers in Unicode: [character.construction/numbers](https://character.construction/numbers)
Generated with:
```ruby
require "unicode/numeric_value"
require "unicode/name" # https://github.com/janlelis/unicode-name
puts "Codepoint | Character | Numeric Value | Name\n" \
"----------|-----------|---------------|-----\n" +
Unicode::NumericValue.chars.map{ |char|
[
format("U+%.4X", char.unpack("U")[0]).rjust(9),
char.rjust(9),
Unicode::NumericValue.of(char).inspect.rjust(13),
Unicode::Name.of(char)
].join(" | ")
}.join("\n")
```
## Also See
- [unicode-x](https://github.com/janlelis/unicode-x): more Unicode related micro libraries
## MIT License
- Copyright (C) 2016-2025 Jan Lelis . Released under the MIT license.
- Unicode data: https://www.unicode.org/copyright.html#Exhibit1