-
System attributes
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
-
You are overthinking this - C# takes care of that stuff for you.
Code:
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 http://ms-help://MS.VSCC/MS.MSDNVS/c...matstrings.htm for more details.
-
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?
-
Why bother? Your way is crude and ugly. Let the framework take care of it.