Problem
The problem is that this overload TryParsetakes this number as a NumberStyles.Integer- meaning it is looking for a format that does not contain .. seeing the Help source , this actually does it:
public static bool TryParse(String s, out Int16 result) {
return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
}
To show that .this is a problem change, as indicated below, and this will work:
decimal myDecimal = 19M;
var succeeded = short.TryParse(myDecimal.ToString(), out newVal);
Like Double work but decimal error
, double , - , ToString:
decimal val1 = 19.00M;
double val2 = 19.00;
val1.ToString()
val2.ToString()
, , NumberStyle Format:
var succeeded = short.TryParse(myDecimal.ToString(), NumberStyles.Number, NumberFormatInfo.CurrentInfo, out newVal);
NumberStyle.Number :
AllowLeadingWhite, AllowTrailingWhite, AllowLeadingSign,
AllowTrailingSign, AllowDecimalPoint, AllowThousands