How to remove decimal part from a number in C#

后端 未结 7 762
予麋鹿
予麋鹿 2020-12-08 04:12

I have number of type double. double a = 12.00 I have to make it as 12 by removing .00

Please help me

相关标签:
7条回答
  • 2020-12-08 04:42

    Well 12 and 12.00 have exactly the same representation as double values. Are you trying to end up with a double or something else? (For example, you could cast to int, if you were convinced the value would be in the right range, and if the truncation effect is what you want.)

    You might want to look at these methods too:

    • Math.Floor
    • Math.Ceiling
    • Math.Round (with variations for how to handle midpoints)
    • Math.Truncate
    0 讨论(0)
提交回复
热议问题