Jared Jared - 1 year ago 153
C# Question

c# how to convert Int/Decimal to float

This is one of those silly intro questions, but 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.

Answer Source

You can just do a cast

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


decimal val3 = 3;
float val4 = (float)val3;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download