I have this line of code in c# but i it always resets the textbox back to the format 0.00, how can i make it so that it keeps the format 0.000 ?.
NewYorkTax = Convert.ToDecimal(txtNewYorkTax.Text);
//converts it but with 0.00, I need 0.000 or 7.861 etc..
SIDE NOTE:
NewYorkTax is of type Decimal, I need to keep this variable.. any ideas?
Thank you
You need to format the string in your textbox:
EDIT: Clarified the use of
String.FormatSecond edit: Regarding exceptions
Also bear in mind the risk of converting to decimal when taking in human input. Humans are error-prone creatures. 🙂
It helps to use
TryParse, whichDecimalsupports: