|
-
September 18th, 2002, 10:05 AM
#1
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
-
September 18th, 2002, 01:39 PM
#2
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.
-
September 18th, 2002, 01:51 PM
#3
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?
-
September 20th, 2002, 08:30 AM
#4
Why bother? Your way is crude and ugly. Let the framework take care of it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|