Skip to content

Instantly share code, notes, and snippets.

@hsinjungwu
Last active August 29, 2015 14:08
Show Gist options
  • Save hsinjungwu/d3ca2865bd27ab5222de to your computer and use it in GitHub Desktop.
Save hsinjungwu/d3ca2865bd27ab5222de to your computer and use it in GitHub Desktop.
Convert Integer To Words
using System;
using System.IO;
using System.Threading;
public class CSharpLab
{
public static void Test()
{
string[] chtInt = new string[]{"零","壹","貳","參","肆","伍","陸","柒","捌","玖"};
string[] moneyUnit1 = new string[] {"拾","佰","仟",};
string[] moneyUnit2 = new string[] {"圓整","萬","億","兆"};
string money = "12340567890123";
char[] digit = money.ToCharArray();
Array.Reverse(digit);
string result = string.Empty;
for (int i = digit.Length-1; i >=0 ; i--)
{
int j = int.Parse(digit[i].ToString());
if (i % 4 == 0)
result += chtInt[j] + moneyUnit2[(i/4)];
else result += chtInt[j] + moneyUnit1[i%4-1];
}
Console.WriteLine(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment