Shawn Van Den Berg
Shawn Van Den Berg

Reputation: 27

Changing culture in vb.net causes my double to error

I decided to force culture settings as too stop some formatting problems.

However, now I get errors such as this:

Conversion from string "548568.68" to type 'Double' is not valid

My only change was to add the following:

Threading.Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo("en-ZA") Threading.Thread.CurrentThread.CurrentUICulture = New Globalization.CultureInfo("en-ZA")

Before adding this, it has worked perfectly.

Upvotes: 1

Views: 235

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1063413

Yep, that happens. In en-ZA, . doesn't mean anything; , is decimals, (space) is groups. 548568.68 makes no sense. If you are expecting 548568.68 to parse to "548568 point 68", then you will need to specify a specific culture (usually the invariant culture) in your call to Parse / Convert / etc.

You can see the particulars of this in the .NumberFormat of the selected CultureInfo.

Upvotes: 3

Related Questions