5

I am trying to read some data from a xml file, numbers are saved in forms like "-2.000000e+000"

I tried to use "double.Parse" but it returns the number as -2000000!!!! can someone please tell me what I am doing wrong?

Dumbo
  • 13,555
  • 54
  • 184
  • 288
  • 3
    Possible duplicate of http://stackoverflow.com/questions/64639/convert-from-scientific-notation-string-to-float-in-c? – AlG Sep 15 '11 at 11:54
  • 1
    and this one http://stackoverflow.com/questions/3879463/c-parse-a-number-from-exponential-notation – Samich Sep 15 '11 at 11:55
  • 1
    You might also want to look into this question: http://stackoverflow.com/questions/147801/best-way-to-parse-float – Michael Sep 15 '11 at 11:56
  • Does allowing `NumberStyles.AllowExponent` make any difference ? – V4Vendetta Sep 15 '11 at 11:57
  • +1 Useful, but in your app's current locale "." in numbers doesn't means a lot, or a fraction delimeter, as it is true in netral (en-US) culture – Alan Turing Sep 15 '11 at 12:02
  • Guys my program worked fine on my own PC but when I brought it to university it did this stupid stuff...I think the problem could be number seperator on the windows of university PC?? damn I have 5 minutes to hand in my assignement! – Dumbo Sep 15 '11 at 12:03

1 Answers1

9

Pass CultureInfo.InvariantCulture to the call to double.Parse:

double.Parse("-2.000000e+000", CultureInfo.InvariantCulture);
Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443