VB.Net: Double results differ in different keyboard language

baabaa_nl used Ask the Experts™
Hi Experts,

Dim strDouble As String = "0" & "." & "01"

Open in new window

The code above simply is stored with three strings, the first and the last values are number and in between is a decimal point.

So according to the code when I print the message I get the value of 0.01.

But I ran the same code on a different computer and I got the result as 1, that is because I developed the code from a US and UK keyboard settings.

But the other computer that I deployed the application on was using European (Dutch keyboard), which instead of a decimal point '.', it uses a comma ','.

Now that I have built the application and has almost a hundred locations on the code with a decimal point. But the users will be using a English keyboard or the Dutch keyboard settings at their own needs . How can I solve this problem to make sure that, even on different language or keyboard settings that my code works as it should be.

Thanks in advance.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
use this to print your value:-

string cultureName = 
            CultureInfo.CurrentCulture.Name.Substring( 0, 2 ) == "nl" ? 
                "en-US" : "nl-NL";
        CultureInfo culture = new CultureInfo( cultureName );

Open in new window

Most Valuable Expert 2012
Top Expert 2014
You would need to change the statement

Dim strDouble As String = "0" & "." & "01"


Dim strDouble As String = "0" & CultureInfo.CurrentCulture.NumberFormat.numberdecimalseparator & "01"


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial