Convert from scientific notation string to float i

2019-01-06 20:27发布

What's the proper way to convert from a scientific notation string such as "1.234567E-06" to a floating point variable using C#?

2条回答
再贱就再见
2楼-- · 2019-01-06 21:12

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.

查看更多
孤傲高冷的网名
3楼-- · 2019-01-06 21:14
Double.Parse("1.234567E-06", System.Globalization.NumberStyles.Float);
查看更多
登录 后发表回答