Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Decimal.Parse() support scientific notation? [duplicate]

Tags:

c#

.net

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?

like image 567
Chris Trombley Avatar asked May 06 '11 20:05

Chris Trombley


People also ask

What does decimal parse do?

Parse(String, NumberStyles, IFormatProvider) Converts the string representation of a number to its Decimal equivalent using the specified style and culture-specific format.

How do you do scientific notation with decimal notation?

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".

Can scientific notation have a decimal?

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.

Can you use scientific notation in Python?

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.


1 Answers

Try something like this:

Decimal.Parse(strExpression, System.Globalization.NumberStyles.AllowExponent));
like image 158
Jonathan Wood Avatar answered Oct 22 '22 14:10

Jonathan Wood