473,396 Members | 1,996 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,396 software developers and data experts.

Help with toString( ) numeric formatting

I'm receiving decimal values from database queries and placing them on a
report page.

The users want to see the following ....

Db Value Display Value
123.3400 123.34
123.0000 123

i.e. I want to trim trailing zeros and (decimal point if no decimal values
occur). This
ought to be really easy but I'm not having much success. Any help would be
GREATLY
appreciated.

I've played with a number of iterations similar to below but the magic
incantation is still
eluding me.

double iDbValue = (double) mDataRow["db_number"];
string sDbValue = iDbValue.ToString("#.##");

Thanks in advance!

Barry
in Oregon
Nov 16 '05 #1
7 3888
Hi BBFrost,

Based on my understanding, you want to do the custom formatting for your
Numeric value.

I see that you have already found the answer to your question.
ToString("#.##") should work for you.

I think you may need a general specification of the numeric formatting.
Actually, in Numeric Format String, "#" is a digit placeholder, while "."
is a Decimal point.

For more information, please refer to:
"Custom Numeric Format Strings"
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconcustomnumericformatstrings.asp

Also, there some samples may help you:
"Custom Numeric Format Strings Output Examples"
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconcustomnumericformatstringsoutputexample.asp

=====================================
Please apply my suggestion above and let me know if it meets your need.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #2
Hi BBFrost,

Based on my understanding, you want to do the custom formatting for your
Numeric value.

I see that you have already found the answer to your question.
ToString("#.##") should work for you.

I think you may need a general specification of the numeric formatting.
Actually, in Numeric Format String, "#" is a digit placeholder, while "."
is a Decimal point.

For more information, please refer to:
"Custom Numeric Format Strings"
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconcustomnumericformatstrings.asp

Also, there some samples may help you:
"Custom Numeric Format Strings Output Examples"
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconcustomnumericformatstringsoutputexample.asp

=====================================
Please apply my suggestion above and let me know if it meets your need.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #3
Jeffery,

Thanks for the quick reply. It's very much appreciated!

Yup, after clearing up a couple of syntax problems ToString("#.##") did
indeed work.

I wrote a quick test program to play with a few of the more common
iterations I'll need eventually ... I've included the Form1.cs in the
message body because of all the problems with attachments these days. I
hope this atones for my somewhat premature post to the group. :-}

B.T.W. I would love to see more examples of the 'fundamental' use of various
Ms Functions in future Ms documentation. Many of the examples in the
current Ms documentation don't seem to address the most fundamental / basic
use making it very difficult to get 'a quick idea' of how a function or
control can be put quickly into play.

Thanks again ...

Barry
in Oregon

================= Test ToString Numeric formatting =====================

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Data.OleDb;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label lblFormattedNbr1_2;
private System.Windows.Forms.Label lblFormattedNbr1_1;
private System.Windows.Forms.Label lblFormattedNbr2_2;
private System.Windows.Forms.Label lblFormattedNbr2_1;
private System.Windows.Forms.Label lblFormattedNbr4_2;
private System.Windows.Forms.Label lblFormattedNbr4_1;
private System.Windows.Forms.Label lblFormattedNbr3_2;
private System.Windows.Forms.Label lblFormattedNbr3_1;
private System.Windows.Forms.Label lblFormattedNbr5_2;
private System.Windows.Forms.Label lblFormattedNbr5_1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label8 = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
this.lblFormattedNbr5_2 = new System.Windows.Forms.Label();
this.lblFormattedNbr5_1 = new System.Windows.Forms.Label();
this.lblFormattedNbr3_2 = new System.Windows.Forms.Label();
this.lblFormattedNbr3_1 = new System.Windows.Forms.Label();
this.lblFormattedNbr4_2 = new System.Windows.Forms.Label();
this.lblFormattedNbr4_1 = new System.Windows.Forms.Label();
this.lblFormattedNbr2_2 = new System.Windows.Forms.Label();
this.lblFormattedNbr2_1 = new System.Windows.Forms.Label();
this.lblFormattedNbr1_2 = new System.Windows.Forms.Label();
this.lblFormattedNbr1_1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// label8
//
this.label8.Location = new System.Drawing.Point(6, 10);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(592, 23);
this.label8.TabIndex = 22;
this.label8.Text = "Instructions:";
this.label8.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// panel1
//
this.panel1.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Controls.Add(this.lblFormattedNbr5_2);
this.panel1.Controls.Add(this.lblFormattedNbr5_1);
this.panel1.Controls.Add(this.lblFormattedNbr3_2);
this.panel1.Controls.Add(this.lblFormattedNbr3_1);
this.panel1.Controls.Add(this.lblFormattedNbr4_2);
this.panel1.Controls.Add(this.lblFormattedNbr4_1);
this.panel1.Controls.Add(this.lblFormattedNbr2_2);
this.panel1.Controls.Add(this.lblFormattedNbr2_1);
this.panel1.Controls.Add(this.lblFormattedNbr1_2);
this.panel1.Controls.Add(this.lblFormattedNbr1_1);
this.panel1.Controls.Add(this.button1);
this.panel1.Controls.Add(this.textBox1);
this.panel1.Controls.Add(this.label1);
this.panel1.Location = new System.Drawing.Point(4, 40);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(594, 338);
this.panel1.TabIndex = 21;
//
// lblFormattedNbr5_2
//
this.lblFormattedNbr5_2.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.lblFormattedNbr5_2.Location = new System.Drawing.Point(224,
186);
this.lblFormattedNbr5_2.Name = "lblFormattedNbr5_2";
this.lblFormattedNbr5_2.Size = new System.Drawing.Size(100, 21);
this.lblFormattedNbr5_2.TabIndex = 12;
this.lblFormattedNbr5_2.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter;
//
// lblFormattedNbr5_1
//
this.lblFormattedNbr5_1.Location = new System.Drawing.Point(26,
186);
this.lblFormattedNbr5_1.Name = "lblFormattedNbr5_1";
this.lblFormattedNbr5_1.Size = new System.Drawing.Size(194, 21);
this.lblFormattedNbr5_1.TabIndex = 11;
this.lblFormattedNbr5_1.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// lblFormattedNbr3_2
//
this.lblFormattedNbr3_2.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.lblFormattedNbr3_2.Location = new System.Drawing.Point(224,
134);
this.lblFormattedNbr3_2.Name = "lblFormattedNbr3_2";
this.lblFormattedNbr3_2.Size = new System.Drawing.Size(100, 21);
this.lblFormattedNbr3_2.TabIndex = 10;
this.lblFormattedNbr3_2.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter;
//
// lblFormattedNbr3_1
//
this.lblFormattedNbr3_1.Location = new System.Drawing.Point(26,
134);
this.lblFormattedNbr3_1.Name = "lblFormattedNbr3_1";
this.lblFormattedNbr3_1.Size = new System.Drawing.Size(194, 21);
this.lblFormattedNbr3_1.TabIndex = 9;
this.lblFormattedNbr3_1.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// lblFormattedNbr4_2
//
this.lblFormattedNbr4_2.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.lblFormattedNbr4_2.Location = new System.Drawing.Point(224,
160);
this.lblFormattedNbr4_2.Name = "lblFormattedNbr4_2";
this.lblFormattedNbr4_2.Size = new System.Drawing.Size(100, 21);
this.lblFormattedNbr4_2.TabIndex = 8;
this.lblFormattedNbr4_2.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter;
//
// lblFormattedNbr4_1
//
this.lblFormattedNbr4_1.Location = new System.Drawing.Point(26,
160);
this.lblFormattedNbr4_1.Name = "lblFormattedNbr4_1";
this.lblFormattedNbr4_1.Size = new System.Drawing.Size(194, 21);
this.lblFormattedNbr4_1.TabIndex = 7;
this.lblFormattedNbr4_1.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// lblFormattedNbr2_2
//
this.lblFormattedNbr2_2.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.lblFormattedNbr2_2.Location = new System.Drawing.Point(224,
108);
this.lblFormattedNbr2_2.Name = "lblFormattedNbr2_2";
this.lblFormattedNbr2_2.Size = new System.Drawing.Size(100, 21);
this.lblFormattedNbr2_2.TabIndex = 6;
this.lblFormattedNbr2_2.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter;
//
// lblFormattedNbr2_1
//
this.lblFormattedNbr2_1.Location = new System.Drawing.Point(26,
108);
this.lblFormattedNbr2_1.Name = "lblFormattedNbr2_1";
this.lblFormattedNbr2_1.Size = new System.Drawing.Size(194, 21);
this.lblFormattedNbr2_1.TabIndex = 5;
this.lblFormattedNbr2_1.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// lblFormattedNbr1_2
//
this.lblFormattedNbr1_2.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.lblFormattedNbr1_2.Location = new System.Drawing.Point(224,
82);
this.lblFormattedNbr1_2.Name = "lblFormattedNbr1_2";
this.lblFormattedNbr1_2.Size = new System.Drawing.Size(100, 21);
this.lblFormattedNbr1_2.TabIndex = 4;
this.lblFormattedNbr1_2.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter;
//
// lblFormattedNbr1_1
//
this.lblFormattedNbr1_1.Location = new System.Drawing.Point(26,
82);
this.lblFormattedNbr1_1.Name = "lblFormattedNbr1_1";
this.lblFormattedNbr1_1.Size = new System.Drawing.Size(194, 21);
this.lblFormattedNbr1_1.TabIndex = 3;
this.lblFormattedNbr1_1.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// button1
//
this.button1.Location = new System.Drawing.Point(224, 38);
this.button1.Name = "button1";
this.button1.TabIndex = 2;
this.button1.Text = "Format Nbr";
this.button1.Click += new
System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.AutoSize = false;
this.textBox1.Location = new System.Drawing.Point(116, 38);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 21);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(26, 38);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(84, 21);
this.label1.TabIndex = 0;
this.label1.Text = "Enter Number:";
this.label1.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(604, 383);
this.Controls.Add(this.label8);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScree n;
this.Text = "Form1";
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
decimal nTestNbr = 0;

try
{
nTestNbr = decimal.Parse(this.textBox1.Text);

lblFormattedNbr1_1.Text = "ToString('#.##')";
lblFormattedNbr1_2.Text = nTestNbr.ToString("#.##");

lblFormattedNbr2_1.Text = "ToString('00.00')";
lblFormattedNbr2_2.Text = nTestNbr.ToString("00.00");

lblFormattedNbr3_1.Text = "ToString('#,#')";
lblFormattedNbr3_2.Text = nTestNbr.ToString("#,#");

lblFormattedNbr4_1.Text = "ToString('##-##-##')";
lblFormattedNbr4_2.Text = nTestNbr.ToString("##-##-##");

lblFormattedNbr5_1.Text = "ToString('(###)###-####')";
lblFormattedNbr5_2.Text =
nTestNbr.ToString("(###)###-####");

}
catch
{
MessageBox.Show("Invalid Number entered.\nPlease try
again\n\n");
}
}
}
}
================================================== ============
""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:WW*************@cpmsftngxa06.phx.gbl...
Hi BBFrost,

Based on my understanding, you want to do the custom formatting for your
Numeric value.

I see that you have already found the answer to your question.
ToString("#.##") should work for you.

I think you may need a general specification of the numeric formatting.
Actually, in Numeric Format String, "#" is a digit placeholder, while "."
is a Decimal point.

For more information, please refer to:
"Custom Numeric Format Strings"
http://msdn.microsoft.com/library/de...us/cpguide/htm l/cpconcustomnumericformatstrings.asp

Also, there some samples may help you:
"Custom Numeric Format Strings Output Examples"
http://msdn.microsoft.com/library/de...us/cpguide/htm l/cpconcustomnumericformatstringsoutputexample.asp

=====================================
Please apply my suggestion above and let me know if it meets your need.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #4
Jeffery,

Thanks for the quick reply. It's very much appreciated!

Yup, after clearing up a couple of syntax problems ToString("#.##") did
indeed work.

I wrote a quick test program to play with a few of the more common
iterations I'll need eventually ... I've included the Form1.cs in the
message body because of all the problems with attachments these days. I
hope this atones for my somewhat premature post to the group. :-}

B.T.W. I would love to see more examples of the 'fundamental' use of various
Ms Functions in future Ms documentation. Many of the examples in the
current Ms documentation don't seem to address the most fundamental / basic
use making it very difficult to get 'a quick idea' of how a function or
control can be put quickly into play.

Thanks again ...

Barry
in Oregon

================= Test ToString Numeric formatting =====================

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Data.OleDb;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label lblFormattedNbr1_2;
private System.Windows.Forms.Label lblFormattedNbr1_1;
private System.Windows.Forms.Label lblFormattedNbr2_2;
private System.Windows.Forms.Label lblFormattedNbr2_1;
private System.Windows.Forms.Label lblFormattedNbr4_2;
private System.Windows.Forms.Label lblFormattedNbr4_1;
private System.Windows.Forms.Label lblFormattedNbr3_2;
private System.Windows.Forms.Label lblFormattedNbr3_1;
private System.Windows.Forms.Label lblFormattedNbr5_2;
private System.Windows.Forms.Label lblFormattedNbr5_1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label8 = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
this.lblFormattedNbr5_2 = new System.Windows.Forms.Label();
this.lblFormattedNbr5_1 = new System.Windows.Forms.Label();
this.lblFormattedNbr3_2 = new System.Windows.Forms.Label();
this.lblFormattedNbr3_1 = new System.Windows.Forms.Label();
this.lblFormattedNbr4_2 = new System.Windows.Forms.Label();
this.lblFormattedNbr4_1 = new System.Windows.Forms.Label();
this.lblFormattedNbr2_2 = new System.Windows.Forms.Label();
this.lblFormattedNbr2_1 = new System.Windows.Forms.Label();
this.lblFormattedNbr1_2 = new System.Windows.Forms.Label();
this.lblFormattedNbr1_1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// label8
//
this.label8.Location = new System.Drawing.Point(6, 10);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(592, 23);
this.label8.TabIndex = 22;
this.label8.Text = "Instructions:";
this.label8.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// panel1
//
this.panel1.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Controls.Add(this.lblFormattedNbr5_2);
this.panel1.Controls.Add(this.lblFormattedNbr5_1);
this.panel1.Controls.Add(this.lblFormattedNbr3_2);
this.panel1.Controls.Add(this.lblFormattedNbr3_1);
this.panel1.Controls.Add(this.lblFormattedNbr4_2);
this.panel1.Controls.Add(this.lblFormattedNbr4_1);
this.panel1.Controls.Add(this.lblFormattedNbr2_2);
this.panel1.Controls.Add(this.lblFormattedNbr2_1);
this.panel1.Controls.Add(this.lblFormattedNbr1_2);
this.panel1.Controls.Add(this.lblFormattedNbr1_1);
this.panel1.Controls.Add(this.button1);
this.panel1.Controls.Add(this.textBox1);
this.panel1.Controls.Add(this.label1);
this.panel1.Location = new System.Drawing.Point(4, 40);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(594, 338);
this.panel1.TabIndex = 21;
//
// lblFormattedNbr5_2
//
this.lblFormattedNbr5_2.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.lblFormattedNbr5_2.Location = new System.Drawing.Point(224,
186);
this.lblFormattedNbr5_2.Name = "lblFormattedNbr5_2";
this.lblFormattedNbr5_2.Size = new System.Drawing.Size(100, 21);
this.lblFormattedNbr5_2.TabIndex = 12;
this.lblFormattedNbr5_2.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter;
//
// lblFormattedNbr5_1
//
this.lblFormattedNbr5_1.Location = new System.Drawing.Point(26,
186);
this.lblFormattedNbr5_1.Name = "lblFormattedNbr5_1";
this.lblFormattedNbr5_1.Size = new System.Drawing.Size(194, 21);
this.lblFormattedNbr5_1.TabIndex = 11;
this.lblFormattedNbr5_1.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// lblFormattedNbr3_2
//
this.lblFormattedNbr3_2.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.lblFormattedNbr3_2.Location = new System.Drawing.Point(224,
134);
this.lblFormattedNbr3_2.Name = "lblFormattedNbr3_2";
this.lblFormattedNbr3_2.Size = new System.Drawing.Size(100, 21);
this.lblFormattedNbr3_2.TabIndex = 10;
this.lblFormattedNbr3_2.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter;
//
// lblFormattedNbr3_1
//
this.lblFormattedNbr3_1.Location = new System.Drawing.Point(26,
134);
this.lblFormattedNbr3_1.Name = "lblFormattedNbr3_1";
this.lblFormattedNbr3_1.Size = new System.Drawing.Size(194, 21);
this.lblFormattedNbr3_1.TabIndex = 9;
this.lblFormattedNbr3_1.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// lblFormattedNbr4_2
//
this.lblFormattedNbr4_2.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.lblFormattedNbr4_2.Location = new System.Drawing.Point(224,
160);
this.lblFormattedNbr4_2.Name = "lblFormattedNbr4_2";
this.lblFormattedNbr4_2.Size = new System.Drawing.Size(100, 21);
this.lblFormattedNbr4_2.TabIndex = 8;
this.lblFormattedNbr4_2.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter;
//
// lblFormattedNbr4_1
//
this.lblFormattedNbr4_1.Location = new System.Drawing.Point(26,
160);
this.lblFormattedNbr4_1.Name = "lblFormattedNbr4_1";
this.lblFormattedNbr4_1.Size = new System.Drawing.Size(194, 21);
this.lblFormattedNbr4_1.TabIndex = 7;
this.lblFormattedNbr4_1.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// lblFormattedNbr2_2
//
this.lblFormattedNbr2_2.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.lblFormattedNbr2_2.Location = new System.Drawing.Point(224,
108);
this.lblFormattedNbr2_2.Name = "lblFormattedNbr2_2";
this.lblFormattedNbr2_2.Size = new System.Drawing.Size(100, 21);
this.lblFormattedNbr2_2.TabIndex = 6;
this.lblFormattedNbr2_2.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter;
//
// lblFormattedNbr2_1
//
this.lblFormattedNbr2_1.Location = new System.Drawing.Point(26,
108);
this.lblFormattedNbr2_1.Name = "lblFormattedNbr2_1";
this.lblFormattedNbr2_1.Size = new System.Drawing.Size(194, 21);
this.lblFormattedNbr2_1.TabIndex = 5;
this.lblFormattedNbr2_1.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// lblFormattedNbr1_2
//
this.lblFormattedNbr1_2.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.lblFormattedNbr1_2.Location = new System.Drawing.Point(224,
82);
this.lblFormattedNbr1_2.Name = "lblFormattedNbr1_2";
this.lblFormattedNbr1_2.Size = new System.Drawing.Size(100, 21);
this.lblFormattedNbr1_2.TabIndex = 4;
this.lblFormattedNbr1_2.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter;
//
// lblFormattedNbr1_1
//
this.lblFormattedNbr1_1.Location = new System.Drawing.Point(26,
82);
this.lblFormattedNbr1_1.Name = "lblFormattedNbr1_1";
this.lblFormattedNbr1_1.Size = new System.Drawing.Size(194, 21);
this.lblFormattedNbr1_1.TabIndex = 3;
this.lblFormattedNbr1_1.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// button1
//
this.button1.Location = new System.Drawing.Point(224, 38);
this.button1.Name = "button1";
this.button1.TabIndex = 2;
this.button1.Text = "Format Nbr";
this.button1.Click += new
System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.AutoSize = false;
this.textBox1.Location = new System.Drawing.Point(116, 38);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 21);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(26, 38);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(84, 21);
this.label1.TabIndex = 0;
this.label1.Text = "Enter Number:";
this.label1.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(604, 383);
this.Controls.Add(this.label8);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScree n;
this.Text = "Form1";
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
decimal nTestNbr = 0;

try
{
nTestNbr = decimal.Parse(this.textBox1.Text);

lblFormattedNbr1_1.Text = "ToString('#.##')";
lblFormattedNbr1_2.Text = nTestNbr.ToString("#.##");

lblFormattedNbr2_1.Text = "ToString('00.00')";
lblFormattedNbr2_2.Text = nTestNbr.ToString("00.00");

lblFormattedNbr3_1.Text = "ToString('#,#')";
lblFormattedNbr3_2.Text = nTestNbr.ToString("#,#");

lblFormattedNbr4_1.Text = "ToString('##-##-##')";
lblFormattedNbr4_2.Text = nTestNbr.ToString("##-##-##");

lblFormattedNbr5_1.Text = "ToString('(###)###-####')";
lblFormattedNbr5_2.Text =
nTestNbr.ToString("(###)###-####");

}
catch
{
MessageBox.Show("Invalid Number entered.\nPlease try
again\n\n");
}
}
}
}
================================================== ============
""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:WW*************@cpmsftngxa06.phx.gbl...
Hi BBFrost,

Based on my understanding, you want to do the custom formatting for your
Numeric value.

I see that you have already found the answer to your question.
ToString("#.##") should work for you.

I think you may need a general specification of the numeric formatting.
Actually, in Numeric Format String, "#" is a digit placeholder, while "."
is a Decimal point.

For more information, please refer to:
"Custom Numeric Format Strings"
http://msdn.microsoft.com/library/de...us/cpguide/htm l/cpconcustomnumericformatstrings.asp

Also, there some samples may help you:
"Custom Numeric Format Strings Output Examples"
http://msdn.microsoft.com/library/de...us/cpguide/htm l/cpconcustomnumericformatstringsoutputexample.asp

=====================================
Please apply my suggestion above and let me know if it meets your need.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #5
Hi BBFrost,

Thanks very much for your feedback.

I am glad my reply makes sense to you. :-)

Actually, I think MSDN has provided you much samples about the usage of
Net Framework classes. But because of the complexity of .Net Framework, we
can not add samples for all the classes and members. MSDN has included
normal usage of the most common classes.

Also, you may get some quick start of using .Net Framework from:
http://samples.gotdotnet.com/quickstart/

Anyway, www.google.com is always the most rich resouce for learning.

There is also a good article and sample site, for your information:
www.codeproject.com

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #6
Hi BBFrost,

Thanks very much for your feedback.

I am glad my reply makes sense to you. :-)

Actually, I think MSDN has provided you much samples about the usage of
Net Framework classes. But because of the complexity of .Net Framework, we
can not add samples for all the classes and members. MSDN has included
normal usage of the most common classes.

Also, you may get some quick start of using .Net Framework from:
http://samples.gotdotnet.com/quickstart/

Anyway, www.google.com is always the most rich resouce for learning.

There is also a good article and sample site, for your information:
www.codeproject.com

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #7
Hi BBFrost,

Does my reply makes sense to you? Do you still have any concern?

Please feel free to let me know, I will help you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #8

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

Similar topics

3
by: RiGGa | last post by:
Hi, I am trung to create a mysql query string that contais two variables, the first holds a table name and the second holds the values as a tuple. I have tried the following however I can not...
0
by: sklett | last post by:
Hi I have code that writes links, these links call a javascript function and pass in a url. So let;s say I have a client side function like this function DoIt( url ) { alert(url); }
6
by: Timo | last post by:
I have this list of checkboxes displaying properly in Opera and IE, but cannot get it in Firefox. For some reason, in FF, the checkboxes creep farther and farther to the right across the page,...
3
by: manning_news | last post by:
Using A2K. I've got a page footer that is displayed only on the last page of the report. There is a subreport, text boxes, and a line for signature in this footer, in that order. If the...
6
by: BBFrost | last post by:
I'm receiving decimal values from database queries and placing them on a report page. The users want to see the following .... Db Value Display Value 123.3400 123.34...
4
by: darrel | last post by:
I'm binding fileinformation to a repeater and attempting to display the 'lastWriteTime' property as a formatted date. This: <%# DataBinder.Eval(Container.DataItem, "LastWriteTime" %> Gives...
1
by: Brad | last post by:
Novice ASP.NET developer ASP.NET 1.1 Windows XP Professional Visual Studio 2003 I've developed a Web application that shows up fine in IE. When I met with my client, who has a Mac, all of the...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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,...

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.