Possible Duplicate:
C# Parse a Number from Exponential Notation
I currently have:
decimal value = Decimal.Parse(dataRow["column"].ToString());
There is some data in the backend that is in scientific notation (ie 3.2661758893885E-05) and which is causing a FormatException on the parse. Is there an easy way to do this?
Parse(String, NumberStyles, IFormatProvider) Converts the string representation of a number to its Decimal equivalent using the specified style and culture-specific format.
To convert a decimal into scientific notation, move the decimal point until you get to the left of the first non-zero integer. The number of places the decimal point moves is the power of the exponent, because each movement represents a "power of 10".
The most common form of scientific notation inserts a decimal point after the first significant digit, follows the significant digits with times, "x", and then 10 to a power. If the original number is at least one, the power is the number of digits between the decimal point and the first number on the left.
Python uses special a syntax to write numbers in Scientific notation. For example, 0.000000123 can be written as 1.23E-7 . The letter E is called exponent and it doesn't matter whether you use e or E . Complex numbers are the numbers which we can't represent on a number line.
Try something like this:
Decimal.Parse(strExpression, System.Globalization.NumberStyles.AllowExponent));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With