I had this same problem these days,
in my case I used javascript with regular expression to correct the error as follows.
Remove all text points.
str = str.replace(/\./g, "");
changes to, per point
str = str.replace(",", ".");
What reason for this? the type fields ( Decimal , numeric
) of SQL SERVER
do not accept ,
to specify the decimal places.
The methods below can help with some things.
// ----- Decimal Extensions -----
public static Boolean IsValidDecimal(this String numStr)
{
Decimal Dummy;
return Decimal.TryParse(numStr.Replace(".", String.Empty),
NumberStyles.Float, new CultureInfo(1046, true), out Dummy);
}
public static Decimal StringToDecimal(this String numStr)
{
return Decimal.Parse(numStr.Replace(".", String.Empty),
NumberStyles.Float, new CultureInfo(1046, true));
}
public static Decimal? StringToNullableDecimal(this String numStr)
{
Decimal? DecVal = null;
if (!numStr.IsNullOrWhiteSpace())
DecVal = numStr.StringToDecimal();
return DecVal;
}
// Converte um Decimal para um String com 2 casos decimais
public static String DecimalToString(this Decimal dec, Int32 scale = 2)
{
return dec.ToString("#,##0.00000000".Substring(0, 6 + scale),
new CultureInfo(1046, true));
}
public static String DecimalToString(this Decimal? dec, Int32 scale = 2)
{
return dec.HasValue ? dec.Value.DecimalToString(scale): String.Empty;
}
public static String DecimalToSqlString(this Decimal dec, Int32 scale = 2)
{
return dec.ToString("0.000000".Substring(0, 2 + scale),
new CultureInfo("en-US", true));
}
public static String DecimalToSqlString(this Decimal? dec, Int32 scale = 2)
{
return dec.HasValue ? dec.Value.DecimalToSqlString(scale) : "null";
}
public static Boolean IsNullOrWhiteSpace(this String str)
{
return String.IsNullOrWhiteSpace(str);
}