Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 2acd7804 authored by Markus QUARITSCH's avatar Markus QUARITSCH
Browse files

refactor 'toDouble' extension method and use tryParse

parent a5dc9fd6
Branches
Tags
No related merge requests found
......@@ -54,14 +54,17 @@ namespace TUGraz.VectoCommon.Utils
throw new FormatException("Cannot convert an empty string to a number.");
}
try {
return double.Parse(self, CultureInfo.InvariantCulture);
} catch (FormatException) {
var success = double.TryParse(self, out var retVal);
if (success) {
return retVal;
}
if (defaultValue.HasValue) {
return defaultValue.Value;
}
throw;
}
// throws an exception
return double.Parse(self, CultureInfo.InvariantCulture);
}
public static int ToInt(this string self, int? defaultValue = null)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment