我有一个十进制值
decimal myDecimal = 19.0000M;
我正在尝试将其转换为短值。
short newVal;
short.TryParse(myDecimal.ToString(), out newVal); // False
但这失败了。如果我使用 double 就没问题。
为什么会失败?
谢谢
最佳答案
包括文化和数字样式将是更好的方法:
short.TryParse(myDecimal.ToString(), NumberStyles.Integer | NumberStyles.AllowDecimalPoint,
System.Globalization.CultureInfo.InvariantCulture, out newVal);
关于c# - 带小数点的 Short.Parse 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40260511/