Convert numbers with exponential notation from string to double or decimal

后端 未结 4 843
栀梦
栀梦 2020-12-11 01:28

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

Update: I found Parse a N

4条回答
  •  失恋的感觉
    2020-12-11 01:44

    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("1.50E-15", CultureInfo.InvariantCulture)
    

提交回复
热议问题