小编Chi*_*nye的帖子

如何检查字符串变量的值是否为double

我正在尝试检查字符串变量的值是否为双精度。

\n\n

我已经看到这个现有问题(检查变量是否为双精度数据类型)及其答案,它们很棒,但我有一个不同的问题。

\n\n
public static bool IsDouble(string ValueToTest) \n    {\n            double Test;\n            bool OutPut;\n            OutPut = double.TryParse(ValueToTest, out Test);\n            return OutPut;\n    }\n
Run Code Online (Sandbox Code Playgroud)\n\n

从上面的代码中,当 ValueToTest 为“-\xe2\x88\x9e”时,变量 Test 中得到的输出为“-Infinity”,并且该方法返回 true。

\n\n

当 ValueToTest 为“NaN”时,我得到的输出为“NaN”。

\n\n

它们都是 C# 中的“-\xe2\x88\x9e”和“NaN”双精度值吗?

\n\n

还有一种方法可以仅检查实数(https://en.wikipedia.org/wiki/Real_number)并排除无穷大和 NaN?

\n

c# string double real-number

3
推荐指数
1
解决办法
8215
查看次数

标签 统计

c# ×1

double ×1

real-number ×1

string ×1