如何转换Int / Decimal在C#中浮动? [英] How do I convert Int/Decimal to float in C#?

查看:486
本文介绍了如何转换Int / Decimal在C#中浮动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要为第三方控件使用一个浮点数,但是我不知道如何将一个浮点数转换为浮点数在代码中使用它们,我不知道如何结束浮动。

解决方案

做一个演员

  int val1 = 1; 
float val2 =(float)val1;

  decimal val3 = 3; 
float val4 =(float)val3;


How does one convert from an int or a decimal to a float in C#?

I need to use a float for a third-party control, but I don't use them in my code, and I'm not sure how to end up with a float.

解决方案

You can just do a cast

int val1 = 1;
float val2 = (float)val1;

or

decimal val3 = 3;
float val4 = (float)val3;

这篇关于如何转换Int / Decimal在C#中浮动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆