I have a textbox bound to a currency data field. So it adds '$' to the start of the text or ($xx.xx) if it's negative. How do I get just the plain double (xx.xx) from the textbox instead of everything ($xx.xx)?
+1
A:
Make sure you set the proper NumberStyles flags when calling double.Parse.
Obviously, you'd use the example below but replace the literal string with a reference to the text in the TextBox.
double d = double.Parse ("$10.10", NumberStyles.Currency);
David Morton
2009-02-04 19:44:22
Great! Thank you. I understand that the '|' is a bitwise OR, but how does it allow me to pass all of those options? I may make a separate question about this.
Malfist
2009-02-04 19:49:46
That big long line can actually be replaced with:Double.Parse("$10.10", System.Globalization.NumberStyles.Currency);And it will handle all of them, including Thousand separators (which you didn't include)
Malfist
2009-02-04 20:00:41
Good catch. So changed.
David Morton
2009-02-04 20:06:58