Rick said:
How do I convert a string value 5.3 to a number for comparision in vs2003
e.g
5.3 >= 5.1
3.9 <= 5.3
Hi Rick,
Use Convert.ToDouble, Convert.ToDecimal or Double.Parse/Double.TryParse,
Decimal.Parse/Decimal.TryParse
If you know the numbers are always valid, Double.Parse is probably easiest
to use, although many would prefer Convert.ToDouble.
double d = double.Parse("5.3");
or
double d = Convert.ToDouble("5.3");
In general the Convert class allows for conversions between many types,
whereas Parse has overloads that allow you to specify number styles and
formats.
// Convert Norwegian floating point numbers
double d = double.Parse("5,3", CultureInfo.GetCultureInfo("nb-NO"));
The TryParse methods are slightly more complicated to use but will never
throw an exception on illegal numbers
double d;
if(double.TryParse("not A Number", out d))
{
// valid number
total += d;
}