This post contains a total of 5+ Hand-Picked C# Decimal to Roman Converter Examples with Source Code. All the Decimal to Roman Converters are made using C Sharp Programming Language.
You can use the source code of these programs for educational use with credits to the original owner.
Related Posts
Click a Code to Copy it.
1. By Ashish Neupane
Made by Ashish Neupane. Simple C# program to convert a decimal number to roman numeral. You can enter the decimal number in the line ” Console.WriteLine(numToRoman(10)); “. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static string numToRoman(int num){
int[] checkpoints = {1,4,5,9,10,40,50,90,100,400,500,900,1000};
string[] numerals = {"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
string roman = "";
int index = checkpoints.Length-1;
while(index>=0){
int repeats = num/checkpoints[index];
num = num%checkpoints[index];
while(repeats--!=0){
roman+=numerals[index];
}
index--;
}
return roman;
}
static void Main(string[] args)
{
Console.WriteLine(numToRoman(10));
}
}
}
2. By Yaitsevolos Dmitry
Made by Yaitsevolos Dmitry. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
int x = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("You Entered {0}, It's Roman Value Is {1}", x, convert(x));
}
public static string convert(int x){
string converted = "";
int y = x;
while(y >= 1000){
y -= 1000;
converted += "M";
}
while(y >= 900){
y -= 900;
converted += "CM";
}
while(y >= 500){
y -= 500;
converted += "D";
}
while(y >= 400){
y -= 400;
converted += "CD";
}
while(y >= 100){
y -= 100;
converted += "C";
}
while(y >= 90){
y -= 90;
converted += "XC";
}
while(y >= 50){
converted += "L";
y -= 50;
}
while(y >= 40){
y -= 40;
converted += "XL";
}
while(y >= 10){
converted += "X";
y -= 10;
}
while(y >= 9){
y -= 9;
converted += "IX";
}
while(y >= 5){
converted += "V";
y -= 5;
}
while(y >= 4){
converted += "IV";
y -= 4;
}
while(y >= 1){
converted += "I";
y -= 1;
}
return converted;
}
}
}
3. By Win Htay 🇲🇲
Made by Win Htay 🇲🇲. The program can Convert Decimal[1-9999] to Roman numerals in easy way. No error handling is done! Writing a fuction is better! ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
string[,] romanNo = new string[,] {{"", "I","II", "III", "IV", "V", "VI", "VII", "VIII", "IX"},
{"", "X","XX","XXX","XL","L","LX","LXX","LXXX","XC"},
{"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM" },
{"", "M", "MM", "MMM", "MMMM", "MMMMM", "MMMMMM", "MMMMMMM", "MMMMMMMM", "MMMMMMMMM" }
};
//Console.WriteLine("Input between 0 an 9999 : ");
string digitSt = Console.ReadLine();
string st="";
for (int i = digitSt.Length - 1; i >= 0; i--)
st += romanNo[i, int.Parse(digitSt[digitSt.Length-1-i].ToString())];
st = string.Format("{0} = {1}",digitSt, st );
Console.WriteLine(st);
}
}
}
4. By Safi Ullah Mirzai
Made by Safi Ullah Mirzai. ( Source )
/*Enter a number and get the roman numeral*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
int n = 0;
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(n);
int thousands = 0;
int hundreds = 0;
int tens = 0;
int units = 0;
if(n>=1000){
thousands = n / 1000;
n -= thousands*1000;
writethousands(thousands);
}
if(n>=100){
hundreds = n / 100;
n = n - hundreds*100;
writehundreds(hundreds);
}
if(n >= 10){
tens = n /10 ;
n = n - tens*10;
writetens(tens);
}
units = n;
writeunits(units);
}
static void writethousands(int x){
switch (x) {
case 5:
Console.Write("V");
break ;
case 4:
Console.Write("MMMM");
break;
case 3:
Console.Write("MMM");
break;
case 2:
Console.Write("MM");
break;
case 1:
Console.Write("M");
break ;
}
}
static void writehundreds(int x){
switch (x){
case 9:
Console.Write("CM");
break;
case 8:
Console.Write("DCCC");
break;
case 7:
Console.Write("DCC");
break;
case 6:
Console.Write("DC");
break;
case 5:
Console.Write("D");
break ;
case 4:
Console.Write("CD");
break;
case 3:
Console.Write("CCC");
break;
case 2:
Console.Write("CC");
break;
case 1:
Console.Write("C");
break ;
}
}
static void writetens(int x){
switch (x){
case 9:
Console.Write("XC");
break;
case 8:
Console.Write("LXXX");
break;
case 7:
Console.Write("LXX");
break;
case 6:
Console.Write("LX");
break;
case 5:
Console.Write("L");
break ;
case 4:
Console.Write("XL");
break;
case 3:
Console.Write("XXX");
break;
case 2:
Console.Write("XX");
break;
case 1:
Console.Write("X");
break ;
}
}
static void writeunits(int x){
switch (x){
case 9:
Console.Write("IX");
break;
case 8:
Console.Write("VIII");
break;
case 7:
Console.Write("VII");
break;
case 6:
Console.Write("VI");
break;
case 5:
Console.Write("V");
break ;
case 4:
Console.Write("IV");
break;
case 3:
Console.Write("III");
break;
case 2:
Console.Write("II");
break;
case 1:
Console.Write("I");
break ;
}
}
}
}
5. By Stack
Made by Stack. ( Source )
using System;
namespace DecimalToRoman
{
/// <summary>
/// Roman Numeral based class
/// </summary>
public class RomanNumeral
{
public string value { get; private set; }
public RomanNumeral(string numeral)
{
if(string.IsNullOrEmpty(numeral))
{
throw new ArgumentNullException(nameof(numeral));
}
value = numeral;
}
/// <summary>
/// Converts the roman numeral to decimal.
/// </summary>
public int ToDecimal()
{
string temp = value.ToLowerInvariant();
char[] ch = temp.ToCharArray();
return Recurse(ch, 0);
}
private int Recurse(char[] chars, int i)
{
if(i == chars.Length)
{
return 0;
}
// vx
int next = Recurse(chars, i+1);
int current = NumeralToDecimal(chars[i]);
if(current < next && chars[i+1] != chars[i])
{
// subtract
return next - current;
}
else
{
// add
// todo: how to deal with overflow?
return current + next;
}
}
private int NumeralToDecimal(char c)
{
switch(c)
{
case 'i': return 1;
case 'v': return 5;
case 'x': return 10;
case 'l': return 50;
case 'c': return 100;
case 'd': return 500;
case 'm': return 1000;
default: throw new ArgumentOutOfRangeException();
}
}
}
}
6. By xDecode
Made by xDecode. ( Source )
using System;
using System.Collections.Generic;
namespace RomanBitte
{
class Program
{
static void Main(string[] args)
{
string res;
res = ToRomanRecursion(24);
System.Console.WriteLine("24 (XXIV) = " + res);
res = ToRomanIteration(3);
System.Console.WriteLine("3 (III) = " + res);
res = ToRomanRecursion(4);
System.Console.WriteLine("4 (IV) = " + res);
res = ToRomanIteration(5);
System.Console.WriteLine("5 (V) = " + res);
res = ToRomanRecursion(6);
System.Console.WriteLine("6 (VI) = " + res);
res = ToRomanIteration(18);
System.Console.WriteLine("18 (XVII) = " + res);
res = ToRomanRecursion(85);
System.Console.WriteLine("85 (LXXXV) = " + res);
res = ToRomanIteration(50);
System.Console.WriteLine("50 (L) = " + res);
res = ToRomanRecursion(80);
System.Console.WriteLine("80 (LXXX) = " + res);
res = ToRomanIteration(94);
System.Console.WriteLine("94 (XCIV) = " + res);
res = ToRomanRecursion(99);
System.Console.WriteLine("99 (XCIX) = " + res);
res = ToRomanIteration(177);
System.Console.WriteLine("177 (CLXXVII) = " + res);
res = ToRomanRecursion(500);
System.Console.WriteLine("500 (D) = " + res);
res = ToRomanIteration(620);
System.Console.WriteLine("620 (DCXX) = " + res);
res = ToRomanRecursion(799);
System.Console.WriteLine("799 (DCCXCIX) = " + res);
res = ToRomanIteration(900);
System.Console.WriteLine("900 (CM) = " + res);
res = ToRomanRecursion(2999);
System.Console.WriteLine("2999 (MMCMXCIX) = " + res);
res = ToRomanRecursion(2013);
System.Console.WriteLine("2013 (MMXIII) = " + res);
res = ToRomanIteration(2845);
System.Console.WriteLine("2845 (MMDCCCXLV) = " + res);
res = ToRomanRecursion(3847);
System.Console.WriteLine("3847 (MMMDCCCXLVII) = " + res);
res = ToRomanRecursion(1300);
System.Console.WriteLine("1300 (MCLXIX) = " + res);
res = ToRomanIteration(2768);
System.Console.WriteLine("2768 (MMDCCLXVIII) = " + res);
res = ToRomanRecursion(3442);
System.Console.WriteLine("3442 (MMMCDXLII) = " + res);
res = ToRomanIteration(3968);
System.Console.WriteLine("3968 (MMMCMLXVIII) = " + res);
res = ToRomanRecursion(4289);
System.Console.WriteLine("4289 (MMMMCCLXXXIX) = " + res);
}
public static string ToRomanIteration(int number)
{
string result = "";
while (number >= 1000)
{
result += "M";
number = number - 1000;
}
while (number >= 900)
{
result += "CM";
number = number - 900;
}
while (number >= 600)
{
result += "DC";
number = number - 600;
}
while (number >= 500)
{
result += "D";
number = number - 500;
}
while (number >= 100)
{
result += "C";
number = number - 100;
}
while (number >= 90)
{
result += "XC";
number = number - 90;
}
while (number >= 50)
{
result += "L";
number = number - 50;
}
while (number >= 40)
{
result += "XL";
number = number - 40;
}
while (number >= 10)
{
result += "X";
number = number - 10;
}
while (number >= 9)
{
result += "IX";
number = number - 9;
}
while (number >= 5)
{
result += "V";
number = number - 5;
}
while (number >= 4)
{
result += "IV";
number = number - 4;
}
while (number >= 1)
{
result += "I";
number = number - 1;
}
return result;
}
public static string ToRomanRecursion(int number)
{
if (number < 1 || number > 4999)
return "";
if (number >= 1000)
return "M" + ToRomanRecursion(number - 1000);
if (number >= 900)
return "CM" + ToRomanRecursion(number - 900);
if (number >= 500)
return "D" + ToRomanRecursion(number - 500);
if (number >= 400)
return "CD" + ToRomanRecursion(number - 400);
if (number >= 100)
return "C" + ToRomanRecursion(number - 100);
if (number >= 90)
return "XC" + ToRomanRecursion(number - 90);
if (number >= 50)
return "L" + ToRomanRecursion(number - 50);
if (number >= 40)
return "XL" + ToRomanRecursion(number - 40);
if (number >= 10)
return "X" + ToRomanRecursion(number - 10);
if (number >= 9)
return "IX" + ToRomanRecursion(number - 9);
if (number >= 5)
return "V" + ToRomanRecursion(number - 5);
if (number >= 4)
return "IV" + ToRomanRecursion(number - 4);
if (number >= 1)
return "I" + ToRomanRecursion(number - 1);
return "";
}
}
}