类型转换问题 [英] problem with type casting
本文介绍了类型转换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用浮点数输入int.
因为我在Windows应用程序中的类型转换方面遇到问题
同时乘以int和float数.
请给我一个解决方案.
how to type int with float.
because I have problem with type casting in windows application
while multiplying with int and float numbers.
pls give me a solution.
推荐答案
您可以使用Convert函数进行类型转换.
例子
you can use Convert function for type casting.
example
float j =5.5;
in i = Convert.ToInt(j);
您可以用代码给我您的要求吗?
can you give me your requirement with code?
如果要对int值进行除法,如果接收变量为double,则必须将它们强制转换为double.
例如,这将导致"0":
If you are dividing int values, you must cast them to doubles if the receiving variable is a double.
For example, this will result in "0":
int x = 1;
int y = 2;
double z = x / y;
这将导致预期的0.5:
Where this will result in the expected 0.5:
int x = 1;
int y = 2;
double z = (double)x / (double)y;
这篇关于类型转换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文