简体   繁体   中英

Convert from scientific notation string to float in C#

使用C#将科学记数法字符串(如“1.234567E-06”)转换为浮点变量的正确方法是什么?

Double.Parse("1.234567E-06", System.Globalization.NumberStyles.Float);

Also consider using

Double.TryParse("1.234567E-06", System.Globalization.NumberStyles.Float, out MyFloat);

This will ensure that MyFloat is set to value 0 if, for whatever reason, the conversion could not be performed. Or you could wrap the Double.Parse() example in a Try..Catch block and set MyFloat to a value of your choosing when an exception is detected.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM