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
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 to share