I need to convert 8.9148E+19
to numeric format using c#
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.
您应该使用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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.