Can someone assist me please am working on the C#.net application I have a method to do validation on the decimal values before insert it to the table which has a column of float type in my database. Here is the method below:
public static bool validateFields(TextBox txtBox)
{
if(txtBox.Text != "")
{
double result = 0.0;
if(!double.TryParse(txtBox.Text, out result))
{
return false;
}
}
return true;
}
My challenge now is when I capture the record of this format ’R12.20’ or updating the record on that is already on the table when hit the validation method where is checking if the value is double or not it’s give me a validation error.
am hooping that am clear on explaining this challenge challenge.
What I have tried:
When I tried the method below with “NumberStayes” and InvariantCulture or CurrentCulture and also change data type to decimal on the method, the cents on the record replaced like R12.20 when I save its save like 12.00 and I update the record again its saved like R1200.00 its keep on increasing
public static bool validateFields(TextBox txtBox)
{
if (txtBox.Text != "")
{
decimal result = 0;
NumberStyles styles = (NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands);
if (!decimal.TryParse(txtBox.Text.Replace(" ", ""), styles, CultureInfo.CurrentCulture, out result))
{
return false;
}
}
return true;
}