I have a variable of decimal type and I want to check the number of digits before decimal point in it.
What should I do? For example, 467.45 should
In order to get an accurate and culturally agnostic answer I do the following:
System.Numerics.BigInteger, whose constructor accepts a decimal and doesn't seem to produce any rounding errors.BigInteger.Abs() to remove any sign.BigInteger.ToString() with the "#" format to suppress any separators that might occur.decimal num = 123213123.123123M;
int length = BigInteger.Abs((BigInteger)num).ToString("#").Length;