473,499 Members | 1,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3195
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
25847
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
1486
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
1671
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
9026
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
4521
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
3347
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
4401
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
7509
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
20641
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
11876
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
7174
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,...
1
6894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7388
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5470
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4600
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3099
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.