Code development platform for open source projects from the European Union institutions

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
No related branches found
No related tags found
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) {
if (defaultValue.HasValue) {
return defaultValue.Value;
}
throw;
var success = double.TryParse(self, out var retVal);
if (success) {
return retVal;
}
if (defaultValue.HasValue) {
return defaultValue.Value;
}
// 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.
Finish editing this message first!
Please register or to comment