Web表格中的数字成单词 [英] Number into words in Web Form
本文介绍了Web表格中的数字成单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友,
我想将总计"值转换为单词格式.
例如:总价值= 32.50
文字格式:像这样的32卢比和50帕兹
请回复
问候,
aamir
Hi Friends,
i want to convert the Total value into the words format.
example: total value=32.50
word format:thirty two ruppes and fifty paise like this
Pl reply
Regards,
aamir
推荐答案
参考:
将数字转换成单词Asp.net C# [如何使用c#转换卢比为单词 [将货币转换为以十万卢比,克劳斯等形式的单词. [ ^ ]
如何将数值或货币转换为英文使用C#的单词 [将数字转换为单词 [ CodeProject [ CodeProject文章 [
Refer:
Convert Numbers into Words Asp.net C#[^]
How do i convert Rupees in words using c#[^]
CP Articles:
Convert Currency To Words in Lakh, Crores, etc.[^]
How to convert a numeric value or currency to English words using C#[^]
Converting Numbers to Words[^]
Have a look on similar QA on CodeProject[^] and CodeProject Articles[^] on same
使用此代码
use this code
public string RupeeInWords(decimal value)
{
return Towords(value);
}
public string Towords(decimal Num)
{
string stmp = ""; int i, leng, prevdigit = 0, digit = 0, pos = 0;
string snum = "", laststr = "";
string pointVlu = "";
string[] sVlu = Convert.ToString(Num).Split('.');
stmp = getInWord(Convert.ToInt32(sVlu[0]));
if (sVlu.Length > 1) pointVlu = getInWord(Convert.ToInt32(sVlu[1]));
if (!pointVlu.Equals(""))
{
if (stmp.Equals(""))
stmp = "Zero ";
stmp += "Rupee and " + pointVlu + " Paisa";
}
return stmp.Trim();
}
string getInWord(int Num)
{
string stmp = ""; int i, leng, prevdigit = 0, digit = 0, pos = 0;
string snum = "", laststr = "";
snum = Convert.ToString(Num);
leng = snum.Length;
#region Loop Process
for (i = leng; i > 0; i--)
{
if (snum.Substring(i - 1, 1) == "-")
{
continue;
}
digit = Convert.ToInt32(snum.Substring(i - 1, 1));
pos = leng - i + 1;
//'1 units
//'3 hundreds
//'4 thousands
//'6 lakhs
//'8 crores
//'10 hundred crores
//'11 thousand crores
//'13 lakh crores
//'15 crore crores
//'sub groups
//'1,8,15
//'3,10
//'4,11
//'6,13
switch (pos)
{
case 1:
case 3:
case 4:
case 6:
case 8:
case 10:
case 11:
case 13:
case 15:
{
if (digit != 0)
{
switch (pos)
{
case 8:
case 15:
laststr = "Crore ";
break;
case 3:
case 10:
laststr = "Hundred ";
break;
case 4:
case 11:
laststr = "Thousand ";
break;
case 6:
case 13:
laststr = "Lakh ";
break;
}
stmp = laststr + stmp;
}
switch (digit)
{
case 0:
if (pos == 1)
laststr = "Zero ";
else
laststr = "";
break;
case 1:
laststr = "One ";
break;
case 2:
laststr = "Two ";
break;
case 3:
laststr = "Three ";
break;
case 4:
laststr = "Four ";
break;
case 5:
laststr = "Five ";
break;
case 6:
laststr = "Six ";
break;
case 7:
laststr = "Seven ";
break;
case 8:
laststr = "Eight ";
break;
case 9:
laststr = "Nine ";
break;
}
stmp = laststr + stmp;
} break;
case 2:
case 5:
case 7:
case 9:
case 12:
case 14:
//'2 tens
//'5 ten thousands
//'7 ten lakhs
//'9 ten crore
//'12 ten thousand crore
//'14 ten lakh crores
{
if (prevdigit == 0)
{
switch (pos)
{
case 9:
laststr = "Crore ";
break;
case 7:
case 14:
if (digit != 0) laststr = "Lakh "; break;
case 5:
case 12:
if (digit != 0) laststr = "Thousand "; break;
}
stmp = laststr + stmp;
}
switch (digit)
{
case 0:
if (prevdigit != 0)
laststr = "And ";
else
laststr = "";
break;
case 1:
switch (prevdigit)
{
case 0:
laststr = "Ten ";
break;
case 1:
stmp = "Eleven " + stmp.Substring(4);
break;
case 2:
stmp = "Twelve " + stmp.Substring(4);
//stmp = stmp.Replace("Two ", "Twelve ");
break;
case 3:
stmp = "Thirteen " + stmp.Substring(6);
//stmp = stmp.Replace("Three ", "Thirteen ");
break;
case 4:
stmp = "Fourteen " + stmp.Substring(5);
/// stmp = stmp.Replace("Four ", "Fourteen ");
break;
case 5:
stmp = "Fifteen " + stmp.Substring(5);
//stmp = stmp.Replace("Five ", "Fifteen ");
break;
case 6:
stmp = "Sixteen " + stmp.Substring(4);
//stmp = stmp.Replace("Six ", "Sixteen ");
break;
case 7:
stmp = "Seventeen " + stmp.Substring(6);
//stmp = stmp.Replace("Seven ", "Seventeen ");
break;
case 8:
stmp = "Eighteen " + stmp.Substring(6);
//stmp = stmp.Replace("Eight ", "Eighteen ");
break;
case 9:
stmp = "Nineteen " + stmp.Substring(5);
//stmp = stmp.Replace("Nine ", "Nineteen ");
break;
} break;
case 2:
laststr = "Twenty "; break;
case 3:
laststr = "Thirty "; break;
case 4:
laststr = "Forty "; break;
case 5:
laststr = "Fifty "; break;
case 6:
laststr = "Sixty "; break;
case 7:
laststr = "Seventy "; break;
case 8:
laststr = "Eighty "; break;
case 9:
laststr = "Ninty "; break;
}
//'if stmp contains "Zero " at the end, remove it
//if InStr(stmp, "Zero ") <> 0 Then stmp = Replace(stmp, "Zero ", "")
stmp = stmp.Replace("Zero ", "");
stmp = laststr + stmp;
} break;
}
prevdigit = digit;
laststr = "";
}
#endregion
return stmp.Trim();
}
这篇关于Web表格中的数字成单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文