convert to float in c# code example
Example 1: C# Cast double to float
double double_Num = 42.0349384093;
float float_Num = (float)dNum;
By Barry Cox
Example 2: c# string to float
class Program
{
static void Main(string[] args)
{
string str1 = "5.682";
string str2 = "4.137";
float flt1 = float.Parse(str1);
float flt2 = float.Parse(str2);
Console.WriteLine(flt1 + flt2);
Console.ReadLine();
}
}
Example 3: float to int c#
Convert.ToInt32(float)
Example 4: c# string to float
string s1 = "1.0"
float f1 = float.Parse(s1);
var ci = (CultureInfo)CultureInfo.CurrentCulture.Clone();
ci.NumberFormat.NumberDecimalSeparator = ",";
string s2 = "1,1";
float f2 = float.Parse(s2, ci);