Click to See Complete Forum and Search --> : System attributes


Chris B.
September 18th, 2002, 10:05 AM
Does anyone know how to retrieve the system attributes. I am specifically looking for what the decimal has been set to. The reason I ask is because not all people use the "." for the decimal and I don't want to hardcode that. I think in Europe they use the ",".

string strParmValue = parmValue.ToString();

int decimalPosition = strParmValue.IndexOf ("."); // Hard-coded decimal
if (decimalPosition == -1)
return -1;
strParmValue = strParmValue.Substring (decimalPosition + 1);

return strParmValue.Length;

I am basically looking for the decimal and returning the number of positions after it.

Thanks

Arild Fines
September 18th, 2002, 01:39 PM
You are overthinking this - C# takes care of that stuff for you.


class A
{
static void Main()
{
double f = 42.354656;
Console.WriteLine( "{0:G}", f );

}
}

This will print out either 42.354656 or 42,354656 depending on your locale settings. There are other format specifiers you can use as well, such as N, D, F, E or C - depending on the format you want. But they will all use your current locale settings. See ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconstandardnumericformatstrings.htm for more details.

Chris B.
September 18th, 2002, 01:51 PM
I am using this.

CultureInfo currentCulture = CultureInfo.CurrentCulture;
string currentDecimal = currentCulture.NumberFormat.CurrencyDecimalSeparator;

int decimalPosition = strParmValue.IndexOf (currentDecimal);
if (decimalPosition == -1)
return -1;
strParmValue = strParmValue.Substring (decimalPosition + 1);

Will this work instead?

Arild Fines
September 20th, 2002, 08:30 AM
Why bother? Your way is crude and ugly. Let the framework take care of it.