PHPackages                             jeronimofagundes/php-roman-numbers - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jeronimofagundes/php-roman-numbers

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

jeronimofagundes/php-roman-numbers
==================================

A helper to convert roman numbers from/to decimal numbers.

v1.0.1(2y ago)14MITPHPPHP ^7.3

Since Jul 29Pushed 2y ago1 watchersCompare

[ Source](https://github.com/jeronimofs/php-roman-numbers)[ Packagist](https://packagist.org/packages/jeronimofagundes/php-roman-numbers)[ RSS](/packages/jeronimofagundes-php-roman-numbers/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (11)Used By (0)

php-roman-numbers
=================

[](#php-roman-numbers)

Support for roman numbers in PHP

Architecture
============

[](#architecture)

It was implemented a simple helper class, namespaced "\\Jeronimofagundes\\Numbers\\Roman\\Helper", which have two methods to convert to and from arabic numbers.

The autoloading was used following PHP FIG's PSR-4 autoloading standards.

The source code is inside the "src" directory. Dependencies are inside "vendor" directory. Tests are inside "tests" folder.

Testing
=======

[](#testing)

To perform unitary tests I used PHPUnit framework. There is one class contaning the tests for the Helper class.

Problem-solving
===============

[](#problem-solving)

Conversion Arabic to Roman
--------------------------

[](#conversion-arabic-to-roman)

The first thing I checked is if the arabic number fits the range \[1-3999\]. This range was defined by [Wikipedia's Roman numerals article](https://en.wikipedia.org/wiki/Roman_numerals).

After that, I fill the input number with zeros to the left so it reaches 4 digits long. Example: 14 turns into 0014.

The next step is convert each character into its corresponding roman. These correspondences are mapped in a constant TO\_ROMAN inside the Helper class. There is mappings for "ones", "tens", "hundreds" and "thousands". This way, the first 0 is ignored, the second one ignored as well, 1 turns into X and 4 turns into IV. That means the returned string is XIV.

Conversion Roman to Arabic
--------------------------

[](#conversion-roman-to-arabic)

This conversion starts checking of the given roman number is valid. I did this using a regular expression.

I mapped some correspondences in a constant FROM\_ROMAN in the Helper class. Using this, I read the roman number in the following way:

1. I start from the most left character.
2. I read two characters. If this correspondence is mapped in the FROM\_ROMAN array, it means it is a subtractive correspondence (like IV, XC or CM), and it gets converted. We move the pointer two characters right and go to step 2 again.
3. If there is no correspondence in the FROM\_ROMAN array, it means it is not a subtractive correspondence. So, we just read one character. That character will have a correspondence in the array, and that value is added to the final result. We move one character to the right and go back to the step two.
4. The processing ends when the roman number is finished.

How to use this library
=======================

[](#how-to-use-this-library)

In order to one use this library, he/she can require it with composer, the standard PHP library package manager.

```
composer require "jeronimofagundes/php-roman-numbers:1.0.0"

```

and use the following class in his/her code:

```
...
use \Jeronimofagundes\Numbers\Roman\Helper;
...
echo Helper::fromArabic(2019); // prints MMXIX
echo Helper::toArabic('MMXIX'); // prints 2019
...

```

I included a file named example.php showing how to use the library. To run it, follow this steps:

1. Clone this repository and cd into it ```
    git clone https://github.com/jeronimofs/php-roman-numbers.git
    cd php-roman-numbers
    ```
2. . Pull the docker image ```
    docker pull jeronimofagundes/php-composer:latest
    ```
3. Install the dependencies with composer ```
    docker run -it -u="$UID" -v $PWD:/app -w="/app" jeronimofagundes/php-composer:latest composer install
    ```
4. Run the file example.php: ```
    docker run -it -u="$UID" -v $PWD:/app -w="/app" jeronimofagundes/php-composer:latest php example.php
    ```

How to test it
==============

[](#how-to-test-it)

We need to use PHPUnit to execute the tests, and we will do it using docker. Follow this steps:

1. Clone this repository and cd into it ```
    git clone https://github.com/jeronimofs/php-roman-numbers.git
    cd php-roman-numbers
    ```
2. Pull the docker image ```
    docker pull jeronimofagundes/php-composer:latest
    ```
3. Run PHPUnit ```
    docker run -it -u="$UID" -v $PWD:/app -w="/app" jeronimofagundes/php-composer:latest /app/phpunit --bootstrap /app/vendor/autoload.php /app/tests
    ```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~169 days

Recently: every ~381 days

Total

10

Last Release

951d ago

Major Versions

0.9.7 → 1.0.02019-07-29

PHP version history (2 changes)0.9.0PHP ^7.2

0.9.4PHP ^7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/2ba5de66353cde49f9726c5702f4f9087aadeae074ab72d4bfe4d434e4bd4565?d=identicon)[jeronimofs](/maintainers/jeronimofs)

---

Top Contributors

[![jeronimofs](https://avatars.githubusercontent.com/u/144969029?v=4)](https://github.com/jeronimofs "jeronimofs (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jeronimofagundes-php-roman-numbers/health.svg)

```
[![Health](https://phpackages.com/badges/jeronimofagundes-php-roman-numbers/health.svg)](https://phpackages.com/packages/jeronimofagundes-php-roman-numbers)
```

###  Alternatives

[naffiq/telegram-channel-php

Post to your telegram channel with ease!

124.2k](/packages/naffiq-telegram-channel-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
