Convert.ToInt32(float)
string s1 = "1.0"
float f1 = float.Parse(s1);
// Change the delimiter - (The default delimiter is based on your current CultureInfo)
var ci = (CultureInfo)CultureInfo.CurrentCulture.Clone();
ci.NumberFormat.NumberDecimalSeparator = ",";
string s2 = "1,1";
float f2 = float.Parse(s2, ci);
float.Parse("41.00027357629127");
Convert.ToSingle("41.00027357629127");
// This works with both positive and negative numbers
public float stringToFloat(string str)
{
if(str.Length == 0)return 0;
int startIndex = 0;
if(str[0] == '-') startIndex = 1;
int dotIndex = str.Length;
float ans = 0;
for(int i = startIndex; i < str.Length; i++)
{
if(str[i] == '.')
{
dotIndex = i;
break;
}
}
for(int i = startIndex; i < dotIndex; i++)
{
ans += (float)Mathf.Pow(10,dotIndex - i - 1) * (str[i] - '0');
}
for(int i = dotIndex+1; i < str.Length; i++)
{
ans += (float)(str[i] - '0') / Mathf.Pow(10, i - dotIndex);
}
if(startIndex == 1)
ans = -ans;
return ans;
}
float.Parse("41.00027357629127");