我使用65.34, 65,45, 34.45
一切都回归真......
public void test()
{
string value = "65" 0r "65.0" 0r "1,234.54";
decimal number;
if (Decimal.TryParse(value, out number))
MessageBox.Show(value);
else
MessageBox.Show("Unable to parse '{0}'.", value);
}
这都返回它的十进制..
If I type "0.65" .. I need to show error and it i type "65" it has to be exectued.
答案 0 :(得分:0)
您有两个选择
1.使用Regex
或
2.使用以下方法查找小数位数
static decimal CountDigitsAfterDecimalPoint(decimal decimalNumber)
{
int[] bits = Decimal.GetBits(decimalNumber);
int exponent = bits[3] >> 16;
int result = exponent;
long lowDecimal = bits[0] | (bits[1] >> 8);
while ((lowDecimal % 10) == 0)
{
result--;
lowDecimal /= 10;
}
return result;
}