c# - 如何将这种科学记数法转换为十进制?

标签 c# decimal

在google中搜索后,使用下面的代码仍然无法编译:

decimal h = Convert.ToDecimal("2.09550901805872E-05");   

decimal h2 = Decimal.Parse(
  "2.09550901805872E-05", 
   System.Globalization.NumberStyles.AllowExponent);

最佳答案

您还必须添加 NumberStyles.AllowDecimalPoint:

Decimal.Parse("2.09550901805872E-05", NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint);

MSDN对此很清楚:

Indicates that the numeric string can be in exponential notation. The AllowExponent flag allows the parsed string to contain an exponent that begins with the "E" or "e" character and that is followed by an optional positive or negative sign and an integer. In other words, it successfully parses strings in the form nnnExx, nnnE+xx, and nnnE-xx. It does not allow a decimal separator or sign in the significand or mantissa; to allow these elements in the string to be parsed, use the AllowDecimalPoint and AllowLeadingSign flags, or use a composite style that includes these individual flags.

关于c# - 如何将这种科学记数法转换为十进制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17587588/

相关文章:

c# - C# 中的 double 与十进制舍入

逗号分隔小数的 Javascript 正则表达式

javascript - 如何从 JavaScript 数字中删除小数部分?

c# - 在 for 循环中随机生成一个 int 值。 7 次迭代后,它返回一个非常大的负数。为什么是这样?

c# - 将 memoryStream 作为字符串返回

javascript - 在 Javascript 和 PHP 中十进制到 RGB

python - decimal.Decimal(n) % 1 返回 InvalidOperation, DivisionImpossible for all n >= 100

c# - 为什么我们不能在 Page_Unload 事件上使用 Response.Write?

c# - 为什么 DataTemplate 返回类名而不是控件?

c# - 需要澄清类关系的一些概念。编程新手