如何从C#中的数字中删除小数部分 [英] How to remove decimal part from a number in C#
本文介绍了如何从C#中的数字中删除小数部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数字类型为double。
double a = 12.00
我必须通过删除.00使其变为12
I have number of type double. double a = 12.00 I have to make it as 12 by removing .00
请帮助我
推荐答案
12
和 12.00
完全相同表示为 double
值。您是要以 double
还是其他价格结尾? (例如,如果您确信该值将在正确的范围内,并且您想要的是截断效果,则可以强制转换为 int
。)
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
(具有处理中点的方式) -
Math.Truncate
Math.Floor
Math.Ceiling
Math.Round
(with variations for how to handle midpoints)Math.Truncate
这篇关于如何从C#中的数字中删除小数部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文