1
0

Build-Fixes, string.ParseDecimal

This commit is contained in:
2021-10-24 18:13:52 +02:00
parent b74eb5b958
commit 197ed5e35f
5 changed files with 72 additions and 43 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
@@ -117,5 +118,20 @@ namespace System
return str;
}
/// <summary>
/// Parses a <see cref="string"/> to a <see cref="decimal"/> using culture "de" or invariant.
/// </summary>
/// <param name="decString">The string to parse.</param>
/// <returns></returns>
public static decimal ParseDecimal(this string decString)
{
int dotIndex = decString.LastIndexOf('.');
int commaIndex = decString.LastIndexOf(',');
var culture = dotIndex < commaIndex ? new CultureInfo("de-DE") : CultureInfo.InvariantCulture;
return decimal.Parse(decString, culture);
}
}
}