介绍
您可以在印度风格转换任何金额高达10 Kharab与派萨背景
C#4.0使用代码
下载附件压缩和解压,这是准备测试
你必须具备的。NET Framework 4.0中,在你的电脑安装测试
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Collections;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
class Element
{
long _Key; string _Value;
public Element(long sKey, string sValue) { _Key = sKey; _Value = sValue; }
public long Key { get { return _Key; } }
public string Value { get { return _Value; } }
}
Element[] Arr = new Element[] {new Element(0, ""), new Element(1, "One "), new Element(2, "Two "), new Element(3, "Three "), new Element(4, "Four "),new Element(5, "Five "), new Element(6, "Six "), new Element(7, "Seven "), new Element(8, "Eight "), new Element(9, "Nine "),new Element(10, "Ten "),
new Element(11, "Eleven "), new Element(12, "Twelve "), new Element(13, "Thirteen "), new Element(14, "Fourteen "),new Element(15, "Fifteen "), new Element(16, "Sixteen "), new Element(17, "Seventeen "), new Element(18, "Eighteen "), new Element(19, "Nineteen "),
new Element(20, "Twenty "), new Element(30, "Thirty "), new Element(40, "Forty "), new Element(50, "Fifty "), new Element(60, "Sixty "),new Element(70, "Seventy "), new Element(80, "Eighty "), new Element(90, "Ninety "),
new Element(100, "Hundred "), new Element(1000, "Thousand "),new Element(10000, "Thousand "),new Element(100000, "Lakh "),new Element(1000000, "Lakh "), new Element(10000000, "Crore "),new Element(100000000, "Crore "), new Element(1000000000, "Arab "),new Element(10000000000, "Arab "), new Element(100000000000, "Kharab "),new Element(1000000000000, "Kharab ")};
public Form1()
{
InitializeComponent();
}
private void btnConvert_Click(object sender, EventArgs e)
{
textBox1.Tag = "";
string[] numParts = numericUpDown1.Value.ToString().Split('.');
string[] result = new string[2] { "", "" };
foreach (string num in numParts)
{
int pos = 0; textBox1.Text = "";
string[] vColl = getCSV(Convert.ToDecimal(num)).Split(',');
for (int i = vColl.Length - 1; i >= 0; i--)
{
if (vColl[i].Trim() == "") continue;
pos = pos + vColl[i].Trim().Length;
textBox1.Text = getText(vColl[i], num.Substring(num.Length - pos)) + textBox1.Text;
}
if (Array.FindIndex(numParts, n => n == num) == 0)
result[0] = textBox1.Text;
else
result[1] = textBox1.Text;
}
textBox1.Text = (result[0] != "" ? "Rs." : "") + result[0] + (result[1] != "" ? "And " + result[1] + "Paisa Only" : (result[0] != "" ? "Only" : ""));
}
private string getText(string val, string baseValue)
{
string retVal = ""; int numVal = Convert.ToInt16(val);
if (val.Length == 2)
{
if (numVal < 20)
retVal = FindElement(numVal);
else
retVal = FindElement(getCeil(val)) + FindElement(Convert.ToInt64(val.Substring(1, 1)));
}
else
if (val != "0") retVal = FindElement(numVal);
if (baseValue.Length >= 3) // >=100
retVal = retVal + FindElement(getCeil(baseValue));
return retVal;
}
string FindElement(long key)
{
return Array.Find(Arr, delegate(Element e) { return e.Key == key; }).Value;
}
private long getCeil(string val)
{
long div = Convert.ToInt64("1".PadRight(val.Length, '0'));
long cVal = (long)( Convert.ToInt64(val) / div) * div;
return Convert.ToInt64(val) >= 100 ? cVal > 0 ? div : cVal : cVal;
}
private string getCSV(decimal val)
{
string s = Regex.Replace(val.ToString("c", CultureInfo.CreateSpecificCulture("gu-IN")), @"\.\d{2}", "");
if (s.Length >= 3) s = s.Insert(s.Length - 2, ",");
return Regex.Replace(s.Substring(3),"^,","");
}
}
}
景点
你编写代码的同时,学到什么有趣的/好玩/恼人的?你做了什么特别聪明或野生或滑稽?历史
于2011年8月10日更新
你可以联系我} {A0时间