Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net I';m无法访问双重数据类型,FormatException_Asp.net - Fatal编程技术网

Asp.net I';m无法访问双重数据类型,FormatException

Asp.net I';m无法访问双重数据类型,FormatException,asp.net,Asp.net,错误是 输入字符串的格式不正确 代码: 通常,此错误与您尚未指定区域性有关。不同的文化有不同的数字书写方式。例如,在我的国家,我们使用“,”作为十进制分隔符,而不是“不变量” 或者(或者结合指定区域性),您可以捕获格式异常并以某种方式进行处理 double d; try { d = Convert.ToDouble("whatever", CultureInfo.InvariantCulture); } catch(FormatException) { // pars

错误是

输入字符串的格式不正确

代码:


通常,此错误与您尚未指定区域性有关。不同的文化有不同的数字书写方式。例如,在我的国家,我们使用“,”作为十进制分隔符,而不是“不变量”

或者(或者结合指定区域性),您可以捕获格式异常并以某种方式进行处理

  double d;
  try {
    d = Convert.ToDouble("whatever", CultureInfo.InvariantCulture);
  } catch(FormatException) {
    // parsing error
    d = -1;
  }

您使用的是什么文化,输入的文本是什么?您的文本框中可能有货币字符?只能将数字数据转换为双精度。也就是说,5.00美元不能兑换成5.0美元
  var d = 5.5;
  Console.Out.WriteLine(d.ToString(CultureInfo.InvariantCulture));
  // yields 5.5
  Console.Out.WriteLine(d.ToString(CultureInfo.GetCultureInfo(1029)));
  // yields 5,5 (czech culture)
  d = Convert.ToDouble("5,5", CultureInfo.InvariantCulture);
  // 55
  d = Convert.ToDouble("5,5", CultureInfo.GetCultureInfo(1029));
  // 5.5
  double d;
  try {
    d = Convert.ToDouble("whatever", CultureInfo.InvariantCulture);
  } catch(FormatException) {
    // parsing error
    d = -1;
  }