C# vs. J# String behavior with non-US regional settings

J

John

Hi,

The following behavior when using J# vs. C# is really bothering me.
When I have the regional settings on my workstation set to a non-US
settings [to test software behavior for international users](eg:
Danish); it seems that J# disregards the regional settings. Where-as
C# automatically picks up the regional settings and applies them.

For example, the following J# code:
public static void main(String[] args)
{
double d = 29.97;
String str = "Here is a floating point number:: " + d + "\n";
System.Console.WriteLine (str);
}

will always output: Here is a floating point number:: 29.97
regardless of what the regional settings are specified as.

The following C# code:
static void Main(string[] args)
{
double d = 29.97;
string str = "Here is a floating point number: " + d + "\n";
Console.WriteLine (str);
}

will output: Here is a floating point number:: 29.97
when the regional settings are set to English-US
but will correctly output:
Here is a floating point number:: 29,97
when the regional settings are set to Danish (with a locale of the
Netherlands)

I run into big problems if a J# assembly is feeding input to a C#
assembly. The C# assembly automatically adjusts to the regional
settings and will reject the J# values if they differ from what a
valid value in the region would be.

Using the example above, the J# output of 29.97 when processed by a C#
assembly (with the regional settings of Danish); will throw an invalid
format exception if you attempt to change the string back into a
double.

Is there any easy way to have the J# routines adhere to the specified
regional settings?

Thanks for any help.

-john
 
M

Mattias Sjögren

Is there any easy way to have the J# routines adhere to the specified
regional settings?

If you explicitly call d.ToString() you have full control over the
formatting.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top