Remove decimal point from a decimal number

前端 未结 7 2135
佛祖请我去吃肉
佛祖请我去吃肉 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:49

    If you always want the printed value to include 2 digits for consistency, you can just multiple by 100 and truncate the result.

    value = Math.Truncate(value * 100m);
    

    This would provide the value you specified in both cases, but also provide a similar result for 2353.6 (-> 235360).

提交回复
热议问题