转换字符串到浮点数在C# [英] Converting String To Float in C#

查看:192
本文介绍了转换字符串到浮点数在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将字符串转换成这样的41.00027357629127,我使用;

I am converting a string like this "41.00027357629127" and I am using;

Convert.ToSingle("41.00027357629127");

float.Parse("41.00027357629127");

这些方法返回4.10002732E + 15

these methods returns 4.10002732E+15

当我转换为浮动我想41.00027357629127这个字符串应该是一样的...

when I convert to float I want "41.00027357629127" this string should be same...

推荐答案

您线程的区域设置为在其中小数标记,而不是。

Your thread's locale is set to one in which the decimal mark is "," instead of ".".

请尝试使用这样的:

float.Parse("41.00027357629127", CultureInfo.InvariantCulture.NumberFormat);

请注意,但是,一个浮动不能认为许多precision数字。你将不得不使用双或小数这样做。

Note, however, that a float cannot hold that many digits of precision. You would have to use double or Decimal to do so.

这篇关于转换字符串到浮点数在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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