Convert a string like "7.2E-05" to decimal C #

    1 answer 1

    string from = "7.2E-05"; double f = double.Parse(from.Replace('.',',')); decimal d =(decimal)f; 

    Or if you combine:

     decimal d = (decimal)double.Parse("7.2E-05".Replace('.',',')); 
    • one
      Replace ('.', ',') - not very good, the parser takes a separator from the regional settings. Better like this: <br> Replace ('.', Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator) - Modus
    • Yeah, right. then you can replace the comma too :) - MaxXx1313
    • @ MaxXx1313, To format a code, select it with the mouse and click on the button 101010 of the editor. - angry