Convert integer to Roman numeral.
Code
Utilitiesconst numerals = [[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 result = '', n = num;
for (const [val, sym] of numerals) {
while (n >= val) { result += sym; n -= val; }
}
return result;Parameters
Integer (1-3999).
Browser·fetch() may be limited by CORS
More JavaScript Snippets
Array to Object
Convert an array of key-value pairs to an object using Object.fromEntries.
Camel Case to Words
Convert a camelCase string to separate words by inserting spaces before capitals.
Convert Currency
Convert between currencies using the Frankfurter API for live exchange rates.
CSV to JSON
Convert a CSV string to a JSON array of objects with headers as keys.
Decimal to Octal
Convert a decimal number to its octal string representation.
JSON to CSV
Convert JSON array to CSV string.