C# Check if a decimal has more than 3 decimal places?

后端 未结 13 1863
一生所求
一生所求 2020-12-03 14:04

I have a situation that I cannot change: one database table (table A) accepts 6 decimal places, while a related column in a different table (table B) only has 3 decimal plac

13条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-03 14:30

    This is a very simple one line code to get count of decimals in a Decimal:

    decimal myDecimal = 1.000000021300010000001m;
    byte decimals = (byte)((Decimal.GetBits(myDecimal)[3] >> 16) & 0x7F);
    

提交回复
热议问题