Convert Int to Float in C#

Haider Ali Mar 04, 2022
Convert Int to Float in C#

This guide will teach us to convert an int to a float in C#. It can be done simply by casting.

We can easily convert an int to a float or decimal using the typecasting method. Let’s take a look.

Convert Int to Float in C#

We can use the type casting to convert an int to float. By writing (float) behind the int variable.

For instance, if your int variable is temp_int, to convert the value inside to a float value, all you need to do is to write (float)temp_int. Take a look at the following code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Int_to_Float
    class Program
        static void Main(string[] args)
            // using type cast we can convert INT TO FLOAT OR DECIMAL...........
            int temp_int = 1;
            float temp_float = (float)temp_int;
            decimal temp_decimal = 3;
            float temp_float_decimal = (float)temp_decimal;
            Console.WriteLine("INT TO FLOAT= "+temp_float);
            Console.WriteLine("FLOAT TO DECIMAL= " + temp_float_decimal   );


The output of the code is given below.

Author: Haider Ali
Haider Ali avatar Haider Ali avatar

Haider specializes in technical writing. He has a solid background in computer science that allows him to create engaging, original, and compelling technical tutorials. In his free time, he enjoys adding new skills to his repertoire and watching Netflix.


Related Article - Csharp Int

Related Article - Csharp Float