You get
Format exception was unhandled ( input string in a incorrect format)
because string.Empty
cannot be converted to a decimal
.
You can use TryParse to inform you if parsing fails:
bool success = decimal.TryParse(_W, out _Wd);
if (success) {
// Use the result
}
else {
// Depending on your needs, do nothing or show an error
}
Note that _W
being string.Empty
may be a condition you want to ignore, while other parse failures might warrant an error message. If so, your else
might look like
else {
if (!string.IsNullOrEmpty(_W)) ShowAnErrorMessageSomehow();
}