Here's my code:
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;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
NumWordsWrapper(3001);
}
static String NumWordsWrapper(double n)
{
string words = "";
double intPart;
double decPart = 0;
if (n == 0)
return "zero";
try
{
string[] splitter = n.ToString().Split('.');
intPart = double.Parse(splitter[0]);
decPart = double.Parse(splitter[1]);
}
catch
{
intPart = n;
}
words = NumWords(intPart);
if (decPart > 0)
{
if (words != "")
words += " and ";
int counter = decPart.ToString().Length;
switch (counter)
{
case 1: words += NumWords(decPart) + " tenths"; break;
case 2: words += NumWords(decPart) + " hundredths"; break;
case 3: words += NumWords(decPart) + " thousandths"; break;
case 4: words += NumWords(decPart) + " ten-thousandths"; break;
case 5: words += NumWords(decPart) + " hundred-thousandths"; break;
case 6: words += NumWords(decPart) + " millionths"; break;
case 7: words += NumWords(decPart) + " ten-millionths"; break;
}
}
return words;
}
}
}
Sorry to waste people's time; this should be a simple thing.
When I click the button, I get the function converting numbers to words, which is great, but it's hard-coded. So, I'm trying to use a TextBox to pass a value to the function.
I think it should be something like this:
private void button1_Click(object sender, EventArgs e)
{
NumWordsWrapper(This.textBox1.Text);
}
That doesn't work!! I've Googled for a solution; haven't come up with anything yet. Any ideas, anyone? this must be a simple thing; I'm just not seeing the solution here.
Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.