Math
ROMAN NUMERALS
Convert between Roman numerals and decimal numbers. Supports 1–3999 with conversion breakdown.
Decimal → Roman
—
⇄
Roman → Decimal
—
Current Year in Roman Numerals
REFERENCE TABLE
| Decimal | Roman | Name |
|---|---|---|
| 1 | I | Unus |
| 4 | IV | Quattuor |
| 5 | V | Quinque |
| 9 | IX | Novem |
| 10 | X | Decem |
| 40 | XL | Quadraginta |
| 50 | L | Quinquaginta |
| 90 | XC | Nonaginta |
| 100 | C | Centum |
| 400 | CD | Quadringenti |
| 500 | D | Quingenti |
| 900 | CM | Nongenti |
| 1000 | M | Mille |
Developer Reference
Core Algorithm & Standalone Script
Standalone, zero-dependency JavaScript implementation powering this tool. Free to inspect, copy, and build upon.
const MAP = [[1000,'M'],[900,'CM'],[500,'D'],[400,'CD'],[100,'C'],[90,'XC'],[50,'L'],[40,'XL'],[10,'X'],[9,'IX'],[5,'V'],[4,'IV'],[1,'I']];
function toRoman(n) {
let result = '', parts = [];
for (const [val, sym] of MAP) {
while (n >= val) { result += sym; parts.push(`${sym}=${val}`); n -= val; }
}
return { result, parts };
}
function fromRomanNum(s) {
const vals = { I:1,V:5,X:10,L:50,C:100,D:500,M:1000 };
s = s.toUpperCase();
if (!/^[IVXLCDM]+$/.test(s)) return null;
let total = 0;
for (let i = 0; i < s.length; i++) {
const cur = vals[s[i]], nxt = vals[s[i+1]] || 0;
if (cur < nxt) total -= cur; else total += cur;
}
return total;
}
function fromDec() {
const n = parseInt(document.getElementById('decInput').value);
const errEl = document.getElementById('decErr');
const bd = document.getElementById('breakdown');
errEl.textContent = '';
if (isNaN(n)) { document.getElementById('decOutput').textContent = '—'; bd.style.display = 'none'; return; }
if (n < 1 || n > 3999) { errEl.textContent = 'Range: 1–3999'; document.getElementById('decOutput').textContent = '—'; return; }
const { result, parts } = toRoman(n);
document.getElementById('decOutput').textContent = result;
bd.style.display = '';
bd.innerHTML = `<strong>${n}</strong> = <span class="eq">${result}</span> = ${parts.join(' + ')}`;
}
function fromRom() {
const s = document.getElementById('romInput').value.trim();
const errEl = document.getElementById('romErr');
errEl.textContent = '';
if (!s) { document.getElementById('romOutput').textContent = '—'; return; }
const n = fromRomanNum(s);
if (n === null || n < 1) { errEl.textContent = 'Invalid Roman numeral'; document.getElementById('romOutput').textContent = '—'; return; }
document.getElementById('romOutput').textContent = n;
}
// Current year
const yr = new Date().getFullYear();
document.getElementById('currentYear').textContent = toRoman(yr).result + ' (' + yr + ')';