C #: custom number formatting in languages ​​with hex languages

I'm trying to write a number with custom formatting in a text box from right to left (actually in a list, but whatever). here is the code:

NumberFormatInfo nfi = (NumberFormatInfo)
            CultureInfo.InvariantCulture.NumberFormat.Clone();
nfi.NumberGroupSeparator = " ";
textbox1.Text = (18700).ToString("#,###",nfi);

      

instead 18 700

we get 700 18

. can I fix this (get required 18 700

) without string manipulation after converting the number to string?

+3


source to share


2 answers


Use white space instead of white space . Its a symbol (char)0x00A0

or '\u00A0'

in C #. You can also enter it using the keyboard using Alt+ 255.

So, you can install NumberGroupSeparator

like this:



nfi.NumberGroupSeparator = "\u00A0";

      

+2


source


I think you can do a little trick like this:



textBox1.Text = TurnString((18700).ToString("#,###", nfi));

public static string TurnString(string value)
{
    Stack<string> stack = new Stack<string>();
    foreach(string a in value.Split(' '))
    {
        stack.Push(a);
    }
    string result = string.Empty;
    while(stack.Count>0)
    {
        result += stack.Pop()+' ';
    }
    return result;
}

      

0


source







All Articles