如何将小数转换为整数?
How do I convert a decimal to an int?
使用 Convert.ToInt32
from mscorlib
as in
Use Convert.ToInt32
from mscorlib
as in
decimal value = 3.14m;
int n = Convert.ToInt32(value);
请参阅 MSDN.您也可以使用 Decimal.ToInt32
.同样,请参阅 MSDN.最后,您可以像中一样进行直接投射
See MSDN. You can also use Decimal.ToInt32
. Again, see MSDN. Finally, you can do a direct cast as in
decimal value = 3.14m;
int n = (int) value;
使用显式转换运算符.请参阅 MSDN.
which uses the explicit cast operator. See MSDN.
这篇关于如何在 C# 中将小数转换为 int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!