簡體   English   中英

德國PC上C#中的系統溢出Int16錯誤

[英]System Overflow Int16 Error in C# on German PCs

我在這里有一個問題。 下面是我在美國,英國,南非和澳大利亞等世界各地的PC上運行良好的應用程序的摘要。 但是,在兩台德國同事的計算機上,以下代碼失敗,錯誤為:

System.OverflowException:對於Int16,值太大或太小。

這是發生在Convert.ToInt16步驟。 我想知道這是否可能是因為德國的小數點制是逗號而不是句點? 另外,該示例的fieldItemsValues值為:

[InputText_confirmName,0,2,49.5216,726.6744,303.2712,47.9664,假,0,0,假,0]

所有字符串

string[] widgetProperties = fieldItemValues[0].Split('_');
string widgetType = widgetProperties[0];
string widgetID = widgetProperties[1];
Console.WriteLine("Type: " + widgetType + " ID: " + widgetID);

float widgetLeft = Convert.ToSingle(fieldItemValues[3]);
float widgetTop = Convert.ToSingle(fieldItemValues[4]);
float widgetWidth = Convert.ToSingle(fieldItemValues[5]);
float widgetHeight = Convert.ToSingle(fieldItemValues[6]);

int widgetLeftPx = Convert.ToInt16(widgetLeft * 2.0);
int widgetTopPx = Convert.ToInt16(widgetTop * 2.0);
int widgetWidthPx = Convert.ToInt16(widgetWidth * 2.0);
int widgetHeightPx = Convert.ToInt16(widgetHeight * 2.0);

我想這是您的問題:726.6744

用德語表示法“。” 是千位分隔符,而不是逗號-您必須添加語言環境。 所以英文726.6744變成7,266,744.00

你需要改變

Convert.ToInt16(widgetLeft * 2.0);

NumberStyles style = style = NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands;
Int16.Parse(widgetLeft * 2.0, style, CultureInfo.InvariantCulture);

你可以閱讀更多有關的NumberStyles 這里和關於文化信息在這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM