CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 1999
    Location
    Texas
    Posts
    119

    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

  2. #2
    Join Date
    Oct 2001
    Location
    Norway
    Posts
    265
    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.

  3. #3
    Join Date
    Jun 1999
    Location
    Texas
    Posts
    119
    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?

  4. #4
    Join Date
    Oct 2001
    Location
    Norway
    Posts
    265
    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
  •  





Click Here to Expand Forum to Full Width

Featured