如何在c#中将字符串转换为numberformatinfo [英] How convert string to numberformatinfo in c#

查看:132
本文介绍了如何在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 for float (which is single-presision) type these days. The type double is the most popular floating-point type. If you look at double metrics, in particular, double.MinValue and double.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


这篇关于如何在c#中将字符串转换为numberformatinfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆