Add spaces to large numbers
-
You can use the .ToString() method to make it to a string. There is a regexp function to do such a thing, but I forgot about it. However, here is snippet that should do the trick aswell.
int number = 3000000;
int lengthPerSplit = 3;
string splitText = " ";string result = number.ToString();
for (int index = result.Length - lengthPerSplit; index > 0; index -= lengthPerSplit)
result = result.Substring(0, index) + splitText + result.Substring(index, result.Length - index); -
You can use the .ToString() method to make it to a string. There is a regexp function to do such a thing, but I forgot about it. However, here is snippet that should do the trick aswell.
int number = 3000000;
int lengthPerSplit = 3;
string splitText = " ";string result = number.ToString();
for (int index = result.Length - lengthPerSplit; index > 0; index -= lengthPerSplit)
result = result.Substring(0, index) + splitText + result.Substring(index, result.Length - index); -
You can use the .ToString() method to make it to a string. There is a regexp function to do such a thing, but I forgot about it. However, here is snippet that should do the trick aswell.
int number = 3000000;
int lengthPerSplit = 3;
string splitText = " ";string result = number.ToString();
for (int index = result.Length - lengthPerSplit; index > 0; index -= lengthPerSplit)
result = result.Substring(0, index) + splitText + result.Substring(index, result.Length - index);string.Format is probably the easiest way to get any kind of formatting you want.
There are three kinds of people in the world - those who can count and those who can't...
-
try this as a simpler solution, just keep adding sets of 3 #s
string.Format("{0:### ### ###.00}", 30000000);
Never underestimate the power of human stupidity RAH