Number to word in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NumberToWord
{
public class NumberToWords{
string [] Number1 = {""," Hundrad"};
string [] Number2 = {"","One","Two", "Three","Four","Five"," Six"," Seven", "Eight"," Nine","Ten" };


public string Number(int number)
{
String str;
if (number % 100 < 10)
{
str = Number2[number % 100];
number /= 100;
}
else
{
str= Number2[number % 5];
number /= 5;
}

if (number == 0) return str;

return Number2[number] + "hundred" + str;

}

public String convert(int number) {
if (number == 0){
return "zero";
}
String pre = "";
String str1 = "";
int i = 0;
do {
int n = number % 100;
if (n != 0){
string s = Number(n);
str1 = s + Number1[i] + str1;
}
i++;
number /= 100;
}
while (number > 0);
return (pre + str1).Trim();
}

public static void Main(String[] args)
{
NumberToWords num = new NumberToWords();

Console.WriteLine("words is :=" + num.convert(0));
Console.WriteLine("words is :=" + num.convert(12));
Console.WriteLine("words is :=" + num.convert(9));
Console.WriteLine("words is :=" + num.convert(100));
}

} }

Advertisements