C# 从指数表示法转换为非指数表示法
我试过:C# 从指数表示法转换为非指数表示法,c#,C#,我试过: MessageBox.Show(System.Numerics.BigInteger.Parse("7.56e+011", NumberStyles.Float, CultureInfo.InvariantCulture)); 但它仍然显示为7.56e+011 decimal dec = decimal.Parse("7.7583877127496407E-6", System.Globalization.NumberStyl
MessageBox.Show(System.Numerics.BigInteger.Parse("7.56e+011",
NumberStyles.Float,
CultureInfo.InvariantCulture));
但它仍然显示为7.56e+011
decimal dec = decimal.Parse("7.7583877127496407E-6",
System.Globalization.NumberStyles.Any);
Console.WriteLine(dec);
您的解决方案再次执行从BigInteger到string的隐式转换,如果指数较大,则使用科学表示法 您正在查看数字格式。你可以用它来做 运行以下代码 为您提供以下消息框
通过将格式更改为{0:F0},您可以不指定小数点。此代码甚至不会编译。在末尾添加ToString,您将获得75600000000的价值num@Lloydbiginger.Parse7.56e+011,numberstyle.Float,CultureInfo.InvariantCulture.ToString返回756000000000@IlyaIvanov添加ToString会得到相同的结果output@kr13显示完整的编译示例,以及读取输入并生成输出的代码outputs@IlyaIvanov这是我所有的。我正在从文本文件中读取值,需要显示它,例如使用MessageBox,它将无法编译。无法从BigInteger转换为字符串???对我来说很合适。我看不出这将在何处尝试进行隐式转换。@kr13请查看我的编辑。这显示它正在使用您说需要显示的MessageBox
BigInteger num = System.Numerics.BigInteger.Parse("7.56e+011",
NumberStyles.Float,
CultureInfo.InvariantCulture);
String text = num.ToString("F5"); // New format string, here with 5 digits.
string.Format("{0:F}",System.Numerics.BigInteger.Parse("7.56e+011",
NumberStyles.Float,
CultureInfo.InvariantCulture))