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

**Update:** I found C# Parse a Number from Exponential Notation but the examples won't work for me unless I specified a culture.

Solution:

```
double test = double.Parse("1.50E-15", CultureInfo.InvariantCulture);
```

The standard `double.Parse`

or `decimal.Parse`

methods do the job here.

Examples:

```
// AllowExponent is implicit
var number1 = double.Parse("0.5e10");
Debug.Assert(number1 == 5000000000.0);
// AllowExponent must be given explicitly
var number2 = decimal.Parse("0.5e10", NumberStyles.AllowExponent);
Debug.Assert(number2 == 5000000000m);
```

Also, see the MSDN article *Parsing Numeric Strings* for more information. As long as the `NumberStyles.AllowExponent`

option is specified to the `Parse`

method (which it is by default for `double`

), parsing such strings will work fine.

**NB:** As the questioner points out, the exponential notation of "e10" for example does not work in all cultures. Specifying en-US culture however ensures that it works. I suspect `CultureInfo.InvariantCulture`

should also do the trick.

@Noldorin is correct try this code:

```
string str = "-5e20";
double d = double.Parse(str);
Console.WriteLine(str);
```

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("0.5e10", CultureInfo.InvariantCulture)
```

the Math.Round does it well, it will reder the number so that will remove, here is how to use it:

```
Math.Round(Double.Parse("3,55E-15"),2)
```

Similar Questions

This sort of example for extracting integers from a string is common: string input = 10 blah 20 30 nonsense 40 50; string[] numbers = System.Text.RegularExpressions.Regex.Split(input, @^[\d]); Bu

I'm trying to do the challenge on http://www.cstutoringcenter.com/problems/problems.php?id=2 and I'm having problems converting scientific notation to decimal notation, which I need to add the exponen

Possible Duplicate: Convert a String to Number - Java String s=1,000.0; how can I get double value from this String? thanks for help :)

Given the reprensentation of decimal I have --you can find it here for instance--, I tried to convert a double this way: explicit Decimal(double n) { DoubleAsQWord doubleAsQWord; doubleAsQWord.doubleV

I have the following string: 2.200000000000E+09 If I do the following: float.Parse(2.200000000000E+09) = 2.2E+9 If I do: Int64.Parse(2.200000000000E+09) I was expecting: 2200000000 Instead I ge

i wanted to convert double to float in C, but wanted to preserve the decimal point exactly as possible without any changes... for example, let's say i have double d = 0.1108; double dd = 639728.17000

İ have string like this and i want to convert it to double. string x = 65.50; double y = Convert.ToDouble(x); But the result is 6550.0 i want it to be 65.50. I am using ASP.NET and C#. I think it i

I am having a application in which I have to process very large numbers. Application API gives me number then I had to convert it into the string and send to further processing. Code receives number a

How can i print the numbers of a float/double variable after the decimal point? For example: 435.5644 the output will be 5644 Thanks,

I am trying to make a program that converts decimal numbers or text into binary numbers in Perl. The program asks for user input of a character or string and then prints out the result to the console.

We want to ensure that upto 10 decimal point values are kept while converting a double value to a string. When we tried %e or %f, it will not keep more than 5 decimal points. When we tried %.14f, the

This routine is called a zillion times to create large csv files full of numbers. Is there a more efficient way to to this? static std::string dbl2str(double d) { std::stringstream ss; ss << st

How to convert String to Double value in jasper Reports? I am having two fields in .jrxml file like below <field name=secRate class=java.lang.String/> <field name=secPrice class=java.l

So I am working on this project where I have to read in a CSV file which contains numbers that are represented in scientific notation. So far what I have is to read in each number then convert that nu

I’m getting numbers from a database. Some are stored as double in the database and some are stored as string. What I want to do is count the decimal number of caracters so : 345.34938 would give me a

SetColoursSizes('0', '[Select Colour]', '0', '[Select Size]', 0,585.00,500.00); This is an example of the string I'd like to match in PHP, and then caputre the last two variables, in case, '585.00' a

I would like to fetch some decimal numbers from a string which I receive from a remote service. My issue is that I only want decimals in the string prefixed with either + or -. Here is my current

I'm trying to print a small double number like 6.67e-11, but using Double.toString() returns 0. What can I do to make it print 6.67e-11 (or something similar) instead?

I have a program that I am working on which would effectively convert binary, decimal, or hex numbers to other formats (don't ask why I'm doing this, I honestly don't know). So far I only have a binar

Possible Duplicate: Convert exponential number to decimal in php Is there a way to convert an exponential number to a whole number in PHP using built in functions? A format function? 1.2378147769392

In .NET, I need to convert a decimal amount (money) to a numbers-only string, i.e: 123,456.78 -> 12345678 I thought var dotPos = amount.ToString().LastIndexOf('.'); var amountString = amount.ToStr

Visual studio wont convert my string to decimal Error: Input string was not in a correct format. Code: string test = 123.95; decimal test1 = decimal.parse(test); // string being an int 123 doesnt

Hi all. I have a double number (Ex: 0.000006). I want convert it to string type. But result is 6E-06. I dont want it, i want 0.000006.Thanks you so much double a = 0.000006; string resultString = a

Possible Duplicate: Round double value to 2 decimal places How do I achieve the following conversion from double to a string: 1.4324 => 1.43 9.4000 => 9.4 43.000 => 43 ie I want to r

I have a double and i am trying to convert it to a decimal. When i use decimalformat to achieve this i get the following: public void roundNumber(){ double d = 2.081641999208976E-4; JOptionPane.showMe

Is there a custom or standard library that I can use with objective c to convert a decimal floating point value into Hexadecimal, Binary and Octal NSStrings? I've been looking around a lot but can onl

I'm looking for the best C or C++ code to encode and decode decimal latitude and longitude values from/to double/char. I'd prefer the code convert from double to char[] and vice-versa rather than c++

I have below code: Double a = new Double((123456798/1000000)); //123456798 this value comes from client side as a `int` DecimalFormat df = new DecimalFormat(###.###); log.info(a :+a+ df +df.form

I have two values coming from database i need to convert these values into double i have done like this i ahve just mentioned like this just as local variables string val; string dpayment; and i am

I got this error when I'm trying to convert String into Double on WP7 C#. tokenvalue = Convert.ToDouble(saParsed[i].Replace(., ,)); I getting this error in WP7. A first chance exception of type

I have a float-based storage of decimal by their nature numbers. The precision of float is fine for my needs. Now I want is to perform some more precise calculations with these numbers using double. A

There are tons of topics on here that explain how to convert a string to a decimal, but how do I convert a decimal back to a string? Like if I did this: import decimal dec = decimal.Decimal('10.0') H

This is probably dumb but it's giving me a hard time. I need to convert/format a double to string with a mandatory decimal point. 1 => 1.0 0.2423423 => 0.2423423 0.1 => 0.1 1234 => 1234.0

I'm working with Python Decimal types, up to 8 decimal places, and for very small numbers, by default, they are displayed using exponential notation. I would prefer them to be displayed in non exponen

Is there an efficient method in VB to check if a string can be converted to a double? I'm currently doing this by trying to convert the string to a double and then seeing if it throws an exception. Bu

I would like to convert a number that is stored in scientific notation into a floating point decimal, so I can then perform some comparisons on the data. This is being done in a bash script - here is

How do I convert a string to a decimal in unity javascript?

I have a decimal column in a table defined as decimal(8,3). I would like to include this column in a Select statement, convert it to a varchar and only display two decimal places. I can't seem to find

I have a string matrix where the fields were derived from numbers in scientific notation. I want to convert the character matrix to a data frame and work on the numeric fields. During the matrix to da

I have an integer (representing seconds) which I'm converting to hours by dividing by 3600. I then store the value in a property (type int). If the value contains a decimal point, I convert it by cast

I have this code: Console.WriteLine(What is the price of the product?); Decimal price = Decimal.Parse(Console.ReadLine()); I take a input as a string as either a int or/and decimal number and conve

I want to write a function that takes in 4 arguments, and prints out a string satisfying the following conditions: The decimal should be in string position X (where X is constant). That way, when I p

I am trying to write a method that converts from engineering notation to double. The case I have now is very special! I mean I am not going to look for powers like Mega, Giga and ... I am just looki

How to convert exponential to fixed decimal. example: 2.5e12 ,0.12323e-11 etc

I want to parse string to double but with scientific notation. Please provide ant solution for solving this problem. String str=123434344; Double db=Double.parseDouble(str); System.out.println(Val

I want to save an array with floats to at file with numpy.savetxt(). The floats have to be decimals (so non-exponential!) The code is as follows: wav = 1./w wav = np.array(sorted(wav)) efittet = permf

I have a normal float number such as 1234.567 or 100000. I would like to convert it to a string such that the precision is fixed and the number is in scientific notation. For example, with 5 digit

I have strings and I need to make doubles from them. They're all in format: Blabla 11/moreBla 17-18 That should become 11.1718 Blabla 7/moreBla 8-9 --> 7.89 Blabla 4/moreBla 6-8 --> 4.68

I have a fetched value from CLOB as 50040,40 and stored this is in a variable. Now, I have to put this data into database's column where data type of that column is number(18,3). This value when put i

All began with these simple lines of code: string s = 16.9; double d = Convert.ToDouble(s); d*=100; The result should be 1690.0, but it's not. d is equal to 1689.9999999999998. All I want to do is