[英]Parsing a decimal string to a byte
我在将十进制字符串解析为字节时遇到问题。
这是带有位置数据的数组,通常是整数。但是我已经能够创建一种位置数据为小数的情况,这会使服务器崩溃,因为我似乎无法解析它。
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]);
我一直在尝试使用Math.Round而不成功。 我确实认为我必须四舍五入小数,因为我正在检索X和Y来放置家具单元。
另外,locationData [1] = 6.0000的内容,这是它试图解析的数字/字符串。
我似乎无法解决问题,希望您能有所帮助。
尝试在NumberStyles
和CultureInfo
...中指定AllowDecimalPoint
。
byte newX = byte.Parse(locationData[1],NumberStyles.AllowDecimalPoint,CultureInfo.InvariantCulture);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.