Convert Integer to Roman Numeral using C#
Posted by Samath
Last Updated: January 20, 2024

Roman numerals are an ancient number system but still have uses in the modern world. Roman numerals are used to represent dates, analog clock faces and for indexing. This  C# code will show you how to convert a number into Roman numeral.

Code:

```using System;
using System.Windows.Forms;

namespace IntegertoRomanNumeral
{
public partial class FormConvertor : Form
{
public FormConvertor()
{
InitializeComponent();
}

private void btnconvert_Click(object sender, EventArgs e)
{
lblroman.ResetText();
int number = Convert.ToInt32(txtroman.Text);

if (number.ToString().Trim().Length == 0)
return;

if (number >= 4000)
{
MessageBox.Show("Please enter a number that is less than 4000.",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

txtroman.Focus();
return;
}

String[] roman = new String[] { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" };
int[] decimals = new int[] { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 };

string romanvalue = String.Empty;

for (int i = 0; i < 13; i++)
{
while (number >= decimals[i])
{
number -= decimals[i];
romanvalue += roman[i];
}
}

lblroman.Text = romanvalue;
}
}
}```

C++ Convert an Integer to Roman Numeral
Samath | Jan 20, 2024
Convert Roman numerals to decimal using Java
Samath | Jan 17, 2024
Python program that test if integer values can form a triangle
Samath | Nov 06, 2014
Java program that reads an integer and prints how many digits the number has
Samath | Feb 11, 2021
C++ Summing the digits in an integer
Samath | Jan 06, 2021
Recursive function that find the sum of digits in a integer using C++
Samath | Dec 24, 2014
Summing the Digits in an Integer using Python
Samath | Mar 02, 2015
C program that receives an integer number and determines if it is a prime number
Samath | Jun 01, 2015
C program that takes a non- negative integer number as input and prints its binary representation
Samath | Jan 01, 2017
Java program that reads an integer and prints if it's positive or negative
Samath | Feb 11, 2021
C++ program that prompts the user to input a decimal number and outputs the number rounded to the nearest integer
Samath | Apr 06, 2022
JavaScript program that convert a string to spinal case
SceDev | Mar 28, 2024
How do you use the LOWER function to convert a string to lowercase?
LeoRobs | Jun 08, 2024
How do you use the TRY_CONVERT function to convert data types with error handling?
LeoRobs | Jun 29, 2024