Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Exception Parse.Double
    text
    copied!<p>I have a simple C# Web console application that utilises the HTML Agility Pack to retrieve data from a given website. My code takes a value from a form field and attempts to reconstruct it into inches, the code works! however I was wondering if there was a more correct, simpler way of achieving my goal?</p> <pre><code>string MetricName = "686 x 1981mm, 35mm Thick: £143.01"; var priceGrab = MetricName.Substring(MetricName.LastIndexOf('£') + 1); // 25.4 is what we divide the MM value by to get the inch value const double imp = 25.4; Match firstMeasurements = Regex.Match(MetricName, @"\d+"); Match secondMeasurements = Regex.Match(MetricName, @"x([^,]*)"); Match thicknessMeasurements = Regex.Match(MetricName, @",([^mm]*)"); string firstM = firstMeasurements.Value; //Convert MM to Inches double first = double.Parse(firstM) / imp; string secondM = secondMeasurements.Value; Match secondFixed = Regex.Match(secondM, @"\d+"); string secondM1 = secondFixed.Value; //Convert MM to Inches double second = double.Parse(secondM1) / imp; string thicknessM = thicknessMeasurements.Groups[1].Value; Match thirdFixed = Regex.Match(thicknessM, @"\d+"); //Convert MM to Inches double three = double.Parse(thicknessM) / imp; ImperialVariant = string.Format("{0} x {1}\", {2}\" Thick: £{3}",first.ToString("00"), second.ToString("00"), three.ToString("0.00"), priceGrab); return ImperialVariant; </code></pre> <p>ImperialVariant will then equal to:</p> <blockquote> <p>30 x 78", 1.38" Thick: £143.01</p> </blockquote> <p>My program raises the following exception for an unknown reason. </p> <blockquote> <p>at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt) at System.Double.Parse(String s)</p> </blockquote> <p>Is anybody able to provide some feedback on this??</p> <p>Thank you</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload