Convert string to float in C#

In this article we will discuss about how to convert from a string value into float value in C#.
  • 16180

Here we are converting string into float. For this we will use float.Parse() method.
 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "2.345";
            string ss = "3.723";
            float flt = float.Parse(str);
            float fl = float.Parse(ss);
            Console.WriteLine(flt + fl);
            Console.ReadLine();
        }
    }
}

 


In the above example two string variables str and ss have been taken. When we convert them into float variables using float.Parse() method they gives the sum of both variables i.e. 6.068
  

Ask Your Question 

Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.