Roman numeral converter

Calculate roman numeral converter with clear inputs and assumptions.

Calculate roman numeral converter with clear inputs and assumptions.

Your inputs stay in your browser. Displayed results are rounded to a maximum of 12 significant digits.

Method and assumptions

Method version 1.0.0 · Updated

Calculate

Formula: Calculate roman numeral converter with clear inputs and assumptions.

Calculate roman numeral converter with clear inputs and assumptions.

value
Integer (1 to 3,999)

Results are estimates where noted and depend on the entered assumptions.

Calculate with code

These short examples use the same inputs and core calculation as this tool. Adapt validation and formatting to your application.

JavaScript
const value = 2026;
const symbols = [[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"]];
let n = value, out = ""; for (const [v, s] of symbols) while (n >= v) { out += s; n -= v; }
console.log(out); // MMXXVI
TypeScript
const value = 2026;
const symbols: [number, string][] = [[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"]];
let n = value, out = ""; for (const [v, s] of symbols) while (n >= v) { out += s; n -= v; }
console.log(out); // MMXXVI
Python
def roman(n):
    out = ""
    for value, symbol in [(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")]:
        while n >= value: out += symbol; n -= value
    return out
print(roman(2026))  # MMXXVI
Java
int n = 2026;
int[] values = {1000,900,500,400,100,90,50,40,10,9,5,4,1};
String[] symbols = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
var out = new StringBuilder(); for (int i=0;i<values.length;i++) while(n>=values[i]) { out.append(symbols[i]); n-=values[i]; }
System.out.println(out); // MMXXVI
C#
int n = 2026;
int[] values = [1000,900,500,400,100,90,50,40,10,9,5,4,1];
string[] symbols = ["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"];
var output = new System.Text.StringBuilder(); for (int i=0;i<values.Length;i++) while(n>=values[i]) { output.Append(symbols[i]); n-=values[i]; }
Console.WriteLine(output); // MMXXVI