How to add thousand separators in a mixed string

76 Views Asked by At

I have a mixed string with numbers and operations (only), like "1234567.89+876-5432*10.1234". And each time I click a number, it will add it to that string (so I need to keep it as only 1 string).

I'm trying to add thousand separators (comma). so the results I'm trying to get is "1,234,567.89+876-5,432*10.1234".

Note: It needs to be added automatically as the user typing. Please.

I tried to read about it all over the place, but couldn't figure how to achieve that. Thank you so much for any help.

1

There are 1 best solutions below

0
On

Every time you wanna add a number to the string , convert it into a string and put a comma at the end and then add it to the main string.

if you have a number like 20.

int numb = 20;
string convertedNumb = numb.toString()+",";

and then just add the convertedNumb to the main string

string newMainString = convertedNumb + mainString;

Then probably you need to put that in a event trigger for any key pressed.