473,288 Members | 1,771 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,288 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 3878
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.