I have a string "3.0E-4", it must be a decimal number.
"3.0E-4"
Please advise how to convert to decimal.
You can use AllowExponentand AllowDecimalPointa decimal.Parsemethod like;
AllowExponent
AllowDecimalPoint
decimal.Parse
var result = decimal.Parse("3.0E-4", NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
Try the following:
decimal x = Decimal.Parse("3.0E-4", NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint);
or how
decimal x = Decimal.Parse("3.0E-4", NumberStyles.Any, CultureInfo.InvariantCulture);
.TryParse (.Parse , ):
.TryParse
.Parse
void Main() { var str="3.0E-4"; float d; if (float.TryParse(str, out d)) { Console.WriteLine("d = " + d.ToString()); } else { Console.WriteLine("Not a valid decimal!"); } }
, TryParse.
Source: https://habr.com/ru/post/1613840/More articles:Symfony2: getScheme does not return 'https' - httpsFailed to pass value of type "UITableViewCell" to "AppName.CustomCellName" - iosHeroku trusted proxies - symfonyHow to make autohide v7 appbar when scrollin partially hides it - android - androidWhy does FLOAT give me a more accurate result than DECIMAL? - databasePython - notification of another thread blocked by a subprocess - pythonНайти детей детей gameObject - c#Display AlertDialog in ViewHolder in adapter class RecyclerView - androidLaravel & vue.js - not rendering an imported component - laravelSVG animation back and forth - htmlAll Articles