I had the 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 a , by point
str = str.replace(",", ".");
What is the reason for this? the fields of the type (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);
}
Let me understand better, what appears if you print the value of
TextBox
before recording?– Maniero
Appears 2,5 - but if I insert 2,5 in POSTGRE at the time of insertion it error. Because no kind of postgre data accepts comma, but when I’m manipulating the textbox and I put it in. Replace(",",".") and send the value of txt pro Numeric and Numeric receives the value it already receives without the .
– Lucas Vasconcelos
@Lucasvasconcelos you need to go through more details then. http://answall.com/help/mcve
– Maniero
Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?
– Maniero