[英]Conversion of scientific notation to long numbers using c#?
I need to convert 8.9148E+19
to numeric format using c#我需要使用c#将8.9148E+19
转换为数字格式
I have already tried using Double.Parse(3.58E+14, System.Globalization.NumberStyles.Float)
but it is rounded up the value, but not returned the actual number.我已经尝试过使用Double.Parse(3.58E+14, System.Globalization.NumberStyles.Float)
但它对值进行了四舍五入,但没有返回实际数字。
您应该使用Parse
from decimal
。
var parsed = decimal.Parse("8.9148E+19", System.Globalization.NumberStyles.Float);
If you want to check and convert the exponent value use this:如果要检查和转换指数值,请使用以下命令:
//your value
string val = "8.9148E+19";
//create a dummy
double dummy;
//check if ist valid
bool hasExponential = (val.Contains("E") || val.Contains("e")) && double.TryParse(val, out dummy);
if (hasExponential)
{
//if it is valid parse it
decimal d = decimal.Parse(val, NumberStyles.Float);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.