Dear Members,
I am using Visual Studio 2005 & SQL Server 2005,
I want round off my output (textbox) value to nearest number.
(for example 112.75 to 113.00 and 111.45 to 111.00)with convert its in words
such as (Rupees One Hundred Thirteen only).
Please help me!
Thanking you!
Loading

Satyapriya NayakPosted Dec 24, 2011, 10:11 AM
Try this...
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 Number_to_word_in_csharp
{
public partial class Form1 : Form
{
int n = 0;
string x = null;
public Form1()
{
InitializeComponent();
}
private void Button1_Click(object sender, EventArgs e)
{
string[] a = {
"One",
"Two",
"Three",
"four",
"Five",
"Six",
"Seven",
"Eight",
"Nine",
"Ten",
"Eleven",
"Twelve",
"Thirteen",
"fourteen",
"Fifteen",
"Sixteen",
"Seventeen",
"Eighteen",
"Ninteen"
};
string[] b = {
"Twenty",
"Thirty",
"Fourty",
"Fifty",
"sixty",
"Seventy",
"eighty",
"ninty"
};
x = "";
n = int.Parse(textBox2.Text);
if ((n <= 9999))
{
if ((n > 999 & n <= 9999))
{
x += a[(n / 1000) - 1] + "Thousand";
n = n % 1000;
}
x += " ";
if ((n > 99 & n <= 999))
{
x += a[(n / 100) - 1] + "Hundred";
n = n % 100;
}
x += " ";
if ((n > 19 & n <= 99))
{
x += b[(n / 10) - 2];
n = n % 10;
}
x += " ";
if ((n > 0 & n <= 19))
{
x += a[n - 1];
}
textBox2.Text = "Rupees" + x + " only";
}
else
{
textBox1.Text = ("Number is out of range");
}
}
private void btn_roundoff_Click(object sender, EventArgs e)
{
string s1 = textBox1.Text;
decimal value;
if (decimal.TryParse(s1, out value))
{
value = Math.Round(value);
s1 = value.ToString();
textBox2.Text = s1;
}
}
}
}
Thanks
VulpesPosted Dec 24, 2011, 9:57 AM
Of course, you'll then need to prepend the resulting string with "Rupees " or any other currency you want to use and then append " only" to it.
Satyapriya NayakPosted Dec 24, 2011, 9:30 AM
For round off
Try this...
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 WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string text = textBox1.Text;
decimal value;
if (decimal.TryParse(text, out value))
{
value = Math.Round(value);
text = value.ToString();
MessageBox.Show(text);
}
}
}
}
Thanks