How can I convert a Number to Roman No in asp.Net using c#?
Answer:
static private string Roman(int i)
{
return Thounds(i);
}
static private string Thounds(int i)
{
string strNo = "";
for (int x = 0; x < i / 1000; x++)
{
strNo =strNo+ "M";
}
strNo = strNo + UptoThousand(i % 1000);
return strNo;
}
static private string UptoThousand(int i)
{
string strNo="";
for (int x = 0; x < i/100; x++)
{
strNo = strNo + "C";
}
if (strNo.Length == 4)
{
strNo = "CD";
}
else if (strNo.Length == 5)
{
strNo = "D";
}
else if (strNo.Length == 9)
{
string temp = "CM";
strNo = temp;
}
else if (strNo.Length >5 && strNo.Length <9)
{
string temp = strNo.Substring(0, 5);
temp = "D";
strNo = temp + strNo.Substring(5);
}
strNo = strNo + UptoHundreds(i%100);
return strNo;
}
static private string UptoHundreds(int i)
{
string strNo = "";
int k = i % 10;
for (int x = 0; x < i / 10; x++)
strNo = strNo + "X";
if (strNo.Length == 4)
{
strNo = "IL";
}
else if (strNo.Length == 5)
{
strNo = "L";
}
else if (strNo.Length == 9)
{
string temp = "XC";
strNo=temp ;
}
else if (strNo.Length > 5 && strNo.Length < 9)
{
string temp = strNo.Substring(0, 5);
temp = "L";
strNo = temp + strNo.Substring(5);
}
strNo = strNo + UpToTen(i % 10);
return strNo;
}
static private string UpToTen(int i)
{
string strNo = "";
for (int x = 1; x <= i; x++)
{
strNo = strNo + "I";
}
if (strNo.Length == 4)
{
strNo = "IV";
}
else if (strNo.Length == 5)
{
strNo = "V";
}
else if (strNo.Length == 9)
{
string temp = "IX";
strNo = temp;
}
else if (strNo.Length > 5 && strNo.Length < 9)
{
string temp = strNo.Substring(0, 5);
temp = "V";
strNo = temp + strNo.Substring(5);
}
return strNo;
}
If any one to suggest me OR ask me any thing more then mail me to mnalammwb@gmail.com
Answer:
static private string Roman(int i)
{
return Thounds(i);
}
static private string Thounds(int i)
{
string strNo = "";
for (int x = 0; x < i / 1000; x++)
{
strNo =strNo+ "M";
}
strNo = strNo + UptoThousand(i % 1000);
return strNo;
}
static private string UptoThousand(int i)
{
string strNo="";
for (int x = 0; x < i/100; x++)
{
strNo = strNo + "C";
}
if (strNo.Length == 4)
{
strNo = "CD";
}
else if (strNo.Length == 5)
{
strNo = "D";
}
else if (strNo.Length == 9)
{
string temp = "CM";
strNo = temp;
}
else if (strNo.Length >5 && strNo.Length <9)
{
string temp = strNo.Substring(0, 5);
temp = "D";
strNo = temp + strNo.Substring(5);
}
strNo = strNo + UptoHundreds(i%100);
return strNo;
}
static private string UptoHundreds(int i)
{
string strNo = "";
int k = i % 10;
for (int x = 0; x < i / 10; x++)
strNo = strNo + "X";
if (strNo.Length == 4)
{
strNo = "IL";
}
else if (strNo.Length == 5)
{
strNo = "L";
}
else if (strNo.Length == 9)
{
string temp = "XC";
strNo=temp ;
}
else if (strNo.Length > 5 && strNo.Length < 9)
{
string temp = strNo.Substring(0, 5);
temp = "L";
strNo = temp + strNo.Substring(5);
}
strNo = strNo + UpToTen(i % 10);
return strNo;
}
static private string UpToTen(int i)
{
string strNo = "";
for (int x = 1; x <= i; x++)
{
strNo = strNo + "I";
}
if (strNo.Length == 4)
{
strNo = "IV";
}
else if (strNo.Length == 5)
{
strNo = "V";
}
else if (strNo.Length == 9)
{
string temp = "IX";
strNo = temp;
}
else if (strNo.Length > 5 && strNo.Length < 9)
{
string temp = strNo.Substring(0, 5);
temp = "V";
strNo = temp + strNo.Substring(5);
}
return strNo;
}
If any one to suggest me OR ask me any thing more then mail me to mnalammwb@gmail.com
No comments:
Post a Comment