Attempt 2 to allow for decimal point

This commit is contained in:
Rick Falkvinge
2022-08-10 10:20:51 +02:00
parent b3fea84e7d
commit a3b6f9c52c
+13 -11
View File
@@ -158,6 +158,19 @@ namespace Swarmops.Logic.Support
culture = CultureInfo.CurrentCulture;
}
// If current culture has decimal point, but decimal comma is entered, allow that
if (culture.NumberFormat.CurrencyDecimalSeparator == ".")
{
// If decimal comma in decimal point position, replace with decimal point
if (input.Length > 3 && input[input.Length - 3] == ',')
{
input = input.Substring(0, input.Length - 3) + "." + input.Substring(input.Length - 2, 2);
}
}
// Try current or provided culture first
success = Double.TryParse(input,
@@ -171,17 +184,6 @@ namespace Swarmops.Logic.Support
// Try invariant (US) culture as fallback
// If decimal comma in decimal point position, replace with decimal point
if (input.Length > 3)
{
if (input[input.Length - 3] == ',')
{
input = input.Substring(0, input.Length - 3) + "." + input.Substring(input.Length - 2, 2);
}
}
success = Double.TryParse(input,
NumberStyles.AllowThousands | NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint,
CultureInfo.InvariantCulture, out outputHolder);