melegant Posted April 23, 2004 Posted April 23, 2004 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~ Quote
*Experts* Bucky Posted April 23, 2004 *Experts* Posted April 23, 2004 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(); Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Administrators PlausiblyDamp Posted April 24, 2004 Administrators Posted April 24, 2004 (edited) It may be easier if you explain what you are trying to achieve as the code you posted looks very convoluted Edited March 16, 2007 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
RobEmDee Posted April 30, 2004 Posted April 30, 2004 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. Quote
Administrators PlausiblyDamp Posted April 30, 2004 Administrators Posted April 30, 2004 how about double d = double.Parse(txtNum1.Text) + double.Parse(txtNum2.Text); txtTSCTax.Text = d.ToString("C"); Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.