我假设它是C语言,并更正了语法。你可以反过来实现你的编程语言。如果我选择一个字符串格式的数字,小数点后超过3位,它应该会出错。拒绝值(month2,“10038”);代码行,它正在以预期的方式工作。我不能完全理解你的问题。
string str = "1.2345";
if (str != null && str.Length > 0)
{
bool month2 = validator.validateDecimal(str.Trim());
if (!month2)
{
errors.rejectValue(month2, "10005");
}
if (str.Contains("."))
{
String decValue = str.Substring(0, str.IndexOf("."));
String precisionValue = str.Substring(str.IndexOf(".") + 1);
if (decValue.Length > 9)
{
errors.rejectValue(month2, "10035");
}
if (precisionValue.Length > 3)
{
errors.rejectValue(month2, "10038");
}
}
else if (str.Length > 9)
{
errors.rejectValue(month2, "10035");
}
}