从字符串到双精度或十进制数转换与指数符号 [英] Convert numbers with exponential notation from string to double or decimal

查看:174
本文介绍了从字符串到双精度或十进制数转换与指数符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种快速的方法来转换成数字与指数符号(例如:0.5e10或-5e20)?为十进制或双倍

更新:我发现<一href="http://stackoverflow.com/questions/3879463/c-sharp-parse-a-number-from-exponential-notation">C#解析从指数符号一个号码但对我来说,除非我指定了一个文化的例子是行不通的。

解决方法:

 双重考验= double.Parse(1.50E-15,CultureInfo.InvariantCulture);
 

解决方案

如果你的文化使用作为小数点分隔符,只是 double.Parse (1.50E-15)应该工作。

如果你的文化用别的东西(如),或者你要确保你的应用程序的工作原理相同的每台计算机上,你应该使用<一个href="http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.invariantculture.aspx"><$c$c>InvariantCulture:

  double.Parse(0.5e10,CultureInfo.InvariantCulture)
 

Is there a fast way to convert numbers with exponential notation (examples: "0.5e10" or "-5e20") to decimal or double?

Update: I found C# Parse a Number from Exponential Notation but the examples won't work for me unless I specified a culture.

Solution:

double test = double.Parse("1.50E-15", CultureInfo.InvariantCulture);

解决方案

If your culture uses . as the decimal separator, just double.Parse("1.50E-15") should work.

If your culture uses something else (e.g. ,) or you want to make sure your application works the same on every computer, you should use InvariantCulture:

double.Parse("0.5e10", CultureInfo.InvariantCulture)

这篇关于从字符串到双精度或十进制数转换与指数符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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