none
separate uint by dots into a label RRS feed

  • Question

  • Hi everyone!,

    Note: I might got this explained wrong in the title, let me explain better:

    I have a uint that change label content in wpf,
    that uint gives a clean value like: "2000000000", but I only want to make the num separated by dots like: "2.000.000.000"

    // Get player money
    MoneyLabel.Content = _currentData.CharacerMoney;


    "_currentData.CharacterMoney" represents a uint value,

    uint GetPlayerMoney = _currentData.CurCharacerMoney;

    the value limit is random from 0 ~ 2.000.000.000 only, just in case.

    How I'm going to achieve this please?
    Thanks in advance.


    • Edited by Zuher Laith Sunday, January 21, 2018 10:38 PM
    Sunday, January 21, 2018 10:38 PM

Answers

  • Hello Zuher,

    Try the below custom method.

        public static string Test(uint number)
            {          
                StringBuilder str = new StringBuilder();
                str.Append(number.ToString());       
                int last = str.Length;
                for (int i = last - 3; i > 0; i -= 3)
                {
                    str.Insert(i, '.');
                }
    
                return str.ToString();
            }

    Invoke the method

       uint number = 1000000000;
    
       string result= Test(number);

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Zuher Laith Monday, January 22, 2018 3:00 PM
    Monday, January 22, 2018 2:05 AM
    Moderator

All replies

  • Hello,

     Yes, you can format a string to display various formatting like DataTime, Currency, etc.

     

     https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings

     

      hope this helps  :)

    Monday, January 22, 2018 12:35 AM
  • Hello Zuher,

    Try the below custom method.

        public static string Test(uint number)
            {          
                StringBuilder str = new StringBuilder();
                str.Append(number.ToString());       
                int last = str.Length;
                for (int i = last - 3; i > 0; i -= 3)
                {
                    str.Insert(i, '.');
                }
    
                return str.ToString();
            }

    Invoke the method

       uint number = 1000000000;
    
       string result= Test(number);

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Zuher Laith Monday, January 22, 2018 3:00 PM
    Monday, January 22, 2018 2:05 AM
    Moderator
  • Hello,

     Yes, you can format a string to display various formatting like DataTime, Currency, etc.

     

     https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings

     

      hope this helps  :)

    I'm interested in this, thank you so much!
    Monday, January 22, 2018 3:00 PM

  • This basically made the trick,
    Thank you so much for help!


    • Edited by Zuher Laith Monday, January 22, 2018 3:00 PM
    Monday, January 22, 2018 3:00 PM
  • Check the next solution too (which is probably an example of supported features):

    uint number = 2000000000;

    string text = number.ToString( "#,##0", CultureInfo.GetCultureInfo( "ar-MR" ) );


    • Edited by Viorel_MVP Monday, January 22, 2018 4:11 PM
    Monday, January 22, 2018 4:11 PM