Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Having fun fun trying to find the best way to convert Double values to fit into Text property of TextBox..

 

Ex.

 

//txtNum1 and txtNum2 are two TexBoxes on a form that are adding money

 

 

txtTSCTax.Text = Double.Parse(Convert.ToString((Convert.ToDouble(txtNum1.Text) + Convert.ToDouble(txtNub2.Text)))).ToString("C");

 

 

 

This can't be the way..it just can't be.

 

 

Thanks

Mele~

  • *Experts*
Posted

The MSDN docmentation for Double.ToString(string) makes no reference to a parameter

of "C". What are you trying to do here?

 

Also, the code is redundant because you're converting a double to a string and then

back to a double again.

 

This should be sufficient:

txtTSCTax.Text = (Convert.ToDouble(txtNum1.Text) + Convert.ToDouble(txtNub2.Text)).ToString();

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted
Bucky...the "C" is a format code. Check the System.Globalization.NumberFormatInfo class. The format codes apply a mask when casting a value type to a string....very handy. C is for currency.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...