C# 将十进制字符串解析为字节
我在将十进制字符串解析为字节时遇到问题 这是一个包含位置数据的数组,通常是整数,但我已经能够创建一个位置数据是小数的情况,这使得服务器崩溃,因为我似乎无法解析它C# 将十进制字符串解析为字节,c#,C#,我在将十进制字符串解析为字节时遇到问题 这是一个包含位置数据的数组,通常是整数,但我已经能够创建一个位置数据是小数的情况,这使得服务器崩溃,因为我似乎无法解析它 string[] locationData = Request.Content.Split(' '); int itemID = int.Parse(locationData[0]); byte newX = byte.Parse(locationData[1]); byte newY = byte.Parse(locationData
string[] locationData = Request.Content.Split(' ');
int itemID = int.Parse(locationData[0]);
byte newX = byte.Parse(locationData[1]);
byte newY = byte.Parse(locationData[2]);
这一行告诉我一个错误,输入的格式不正确:
byte newX = byte.Parse(locationData[1]);
我一直在尝试使用数学,但没有成功。我确实认为我必须对小数进行四舍五入,因为我要检索X和Y来放置家具单元
此外,locationData[1]的内容=6.0000,这是它试图解析的数字/字符串
我似乎无法解决这个问题,希望您能提供帮助。尝试在
numberstyle
和CultureInfo
中指定AllowDecimalPoint
byte newX = byte.Parse(locationData[1],NumberStyles.AllowDecimalPoint,CultureInfo.InvariantCulture);
什么样的非小数数字??