473,385 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Number formatting

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

Sujoy

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
7 3190
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

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

Sujoy

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #2
"sujoy kar" <su*******@vsnl.net> wrote in message
news:O%****************@TK2MSFTNGP15.phx.gbl...
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"
Nov 17 '05 #3
> I want to format numeric values while displaying like 0 shouldbe
formatted as 0.00 in windows form in .NET using c#

Here's an example:

string MyFormat = "###0.00;-###0.00";
double d = 123.456;
MyTextBox.Text = d.ToString(MyFormat);

See MSDN for more information:
http://msdn.microsoft.com/library/de...ngoverview.asp

Greetings,
Wessel
Nov 17 '05 #4
> 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
Nov 17 '05 #5
"Wessel Troost" <no*****@like.the.sun> wrote in message
news:op.suxgqhy0f3yrl7@asbel...
string strDouble = dblTest.ToString("#,###0.00"); // displays Shouldn't that be "#,##0.00" ?


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


Er, OK...
Nov 17 '05 #6
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.

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 17 '05 #7
> 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
Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Douglas | last post by:
Gday, How would I format a number so that: TheValue = 32500 Displays in the TextBox as: $32,500.00
0
by: Josh Harris | last post by:
Here is my issue: I have a datagrid that is populated with a datatable. I want the columns of the datagrid to be sortable. I also want to format the numeric columns such as two decimal places...
2
by: Steve Peterson | last post by:
Hi I have an app where I have to deal with both Spanish & American formatting. I have a string that represents a number that I need to convert to Int32 before I enter it in the database. The...
29
by: james | last post by:
I have a problem that at first glance seems not that hard to figure out. But, so far, the answer has escaped me. I have an old database file that has the date(s) stored in it as number of days. An...
4
by: Brian Henry | last post by:
I have phone numbers like this in a data table 123-435-1234 1231231234 432.234.2321 they all have different formatting, what I want to do is get them all formatted like this (123) 123-1234
1
by: womblesjc | last post by:
I have a data bound Details View control in asp.net 2.0 that formats a phone number. The 'Default Mode' for the control is set to Edit. The phone number field is a template field and I can...
2
by: dcyale | last post by:
I have a report with the following paragraph: ="This BA presents a " & & " determination for the " & & " and associated habitat. We would appreciate you processing the biological opinion by " &...
109
by: jmcgill | last post by:
Hello. Is there a method for computing the number of digits, in a given numeric base, of N factorial, without actually computing the factorial? For example, 8! has 5 digits in base 10; 10! has...
9
by: Nebojsa4 | last post by:
Hi. First, sorry on my weak English to all. Qusetion: How to read (in VB) Manufacturer serial number of Hard disk drive? Not volume/serial number of C:, D:, etc. partitons. For reading...
2
Pittaman
by: Pittaman | last post by:
Hello I am creating some crystal reports (for visual studio 2005) based on the content of certain .NET objects. I'm doing this in .NET 2.0. For one of them I'm using a Cross-table to summarize...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.