Number formatting

  • Thread starter Thread starter sujoy kar
  • Start date Start date
S

sujoy kar

I want to format numeric values while displaying like 0 shouldbe
formatted as 0.00 in windows form in .NET using c#



Sujoy
 
You need to use standard number formatting.

For example:

Console.WriteLine("{0:N}", 1);

will write out "1.00" to the console. Since you are using Windows forms and
you probably have an int then you need something like:

int number = 45;
int number2 = 0;

label1.Text = number.ToString("N"); // will display "45.00"
label2.Text = number2.ToString("N"); // will display "0.00"

Hope this helps.

Brian
 
I want to format numeric values while displaying like 0 shouldbe
formatted as 0.00 in windows form in .NET using c#

Have a look at the overloaded .ToString() method. You can use the built-in
formatting, or you can roll your own e.g.

double dblTest = 123456.70123;
string strDouble = dblTest.ToString("#,###0.00"); // displays "123,456.70"

DateTime dtmDate = new DateTime(2005, 8, 3);
string strDate = dtmTest.ToString("dd MMM yyyy"); // displays "03 Aug 2005"
 
string strDouble = dblTest.ToString("#,###0.00"); // displays
Shouldn't that be "#,##0.00" ?

It's funny but your example actually works, because there is never a
fourth digit on the right side of the thousand separator. *hehe*

Greetings,
Wessel
 
I have a DataGrid which is bound to a DataSource using DataBind.I want
to display the numeric fields in the DataGrid of a format so that 0 will
apper as 0.00.Can u help me.
 
I have a DataGrid which is bound to a DataSource using DataBind.I want
to display the numeric fields in the DataGrid of a format so that 0 will
apper as 0.00.Can u help me.
The DataGridTextBoxColumn class has a property called Format. You can set
it to your format string.

Greetings,
Wessel
 
Back
Top