如何在c#中将字符串转换为numberformatinfo
问题描述:
Hello Everybody!
I am trying convert string to NumberFormatInfo but i had trouble: "Value was either too large or too small for a single".
I dont know how fix this error. Please help me! Thank you so much!!!!.
我的尝试:
转换时这是我的代码:
What I have tried:
This is my code when convert:
<pre lang="C#">
public string FValue;
public NumberFormatInfo N = new NumberFormatInfo();
public float FloatValue()
{
try
{
F = Convert.ToSingle(FValue, N);
}
catch (Exception ex)
{
abc.Add(FValue);
MessageBox.Show(ex.ToString());
}
return F;
}
// ex: FValue = -9.255963134931787E+61.
I expect an answer from you!!! Thank you again. :).
答
实际上,float
没有那么多用处(这是单一的)这些天类型。类型double
是最流行的浮点类型。如果您查看double
指标,尤其是double.MinValue
和double.MaxValue
,你会发现它是-1.7976931348623157E + 308到1.7976931348623157E + 308。好多了,不是吗? :-)
CPU还支持80位扩展精度:扩展精度 - 维基百科,免费百科全书 [ ^ ]。
参见:
IEEE浮点 - 维基百科,免费的百科全书 [ ^ ],
IEEE 754-1985 - 维基百科,免费的百科全书 [ ^ ]。-SA
Practically, there is no so much use forfloat
(which is single-presision) type these days. The typedouble
is the most popular floating-point type. If you look atdouble
metrics, in particular,double.MinValue
anddouble.MaxValue
, you will find that it's -1.7976931348623157E+308 to 1.7976931348623157E+308. Much better, isn't it? :-)
The CPU also supports 80-bits "extended precision": Extended precision — Wikipedia, the free encyclopedia[^].
See also:
IEEE floating point — Wikipedia, the free encyclopedia[^],
IEEE 754-1985 — Wikipedia, the free encyclopedia[^].—SA