Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does float.parse return wrong value?

I have a problem. when I parse a string like "0.005" to float or double, it works fine on my computer, but when i install my program to my client's computer, it returns 5. (both my computer and my client's computer are using Windows 7 x64). Here are my examples

public float getFloat()
    {
        float mn = float.Parse("0.005");
        double mn2 = Convert.ToDouble("0.005");
        return mn;
    }
like image 345
Victor Avatar asked May 20 '13 19:05

Victor


1 Answers

It could be problem with system culture settings. Try this:

float.Parse("0.005", CultureInfo.InvariantCulture);
like image 72
mipe34 Avatar answered Nov 08 '22 18:11

mipe34