Build-Fixes, string.ParseDecimal
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user