13

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;
    }
Victor
  • 192
  • 1
  • 2
  • 7
  • 9
    Are you guys using the same culture in your machines? `.` is not the decimal separator in every culture. **Edit:** In PT-BR, for example, 0.005 **IS** 5. – Geeky Guy May 20 '13 at 19:40
  • 1
    that's an interesting broblem you have there. – David Starkey May 20 '13 at 19:40
  • 5
    Yes, the problem is almost definitely that your client's computer is set to use "." as a thousands separator rather than a decimal point, as @Renan alludes to. – Ryan M May 20 '13 at 19:41

1 Answers1

20

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

float.Parse("0.005", CultureInfo.InvariantCulture);
mipe34
  • 5,596
  • 3
  • 26
  • 38