Remove decimal point from a decimal number

前端 未结 7 2209
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-19 01:32

I am trying to remove just the decimal point from a decimal number in C#.

For example:

  • My decimal number is 2353.61 I want 235361
7条回答
  •  遇见更好的自我
    2021-01-19 01:58

    Here it is:

        public decimal RemoveDecimalPoints(decimal d)
        {
            try
            {
                return d * Convert.ToDecimal(Math.Pow(10, (double)BitConverter.GetBytes(decimal.GetBits(d)[3])[2]));
            }
            catch (OverflowException up)
            {
                // unable to convert double to decimal
                throw up; // haha
            }
        }
    

提交回复
热议问题