Hello,
Welcome to our Microsoft Q&A platform!
You could have a try to use String.Format
and #
, it can be formatted by "-""/""?" or some other character , but it can't be formatted by comma.
MyEntry.Text = string.Format("{0:#######-###}", totle);
Because comma turns the number into thousandths. If you want to use comma, you could use NumberFormatInfo
.
double a = 12345678.876555;
int b = 99999;
double totle = a + b;
NumberFormatInfo nfo = new NumberFormatInfo();
nfo.CurrencyGroupSeparator = ",";
nfo.CurrencyGroupSizes = new int[] { 3, 5 };
nfo.CurrencySymbol = "";
MyEntry.Text = totle.ToString("c0", nfo);
In addition, you could insert ,
into string.
//int a = 1;
//int b = 9;
int a = 1111;
int b = 99999999;
double totle = a + b;
string totleString = totle.ToString();
int length = totleString.Length;
MyEntry.Text = length>3?totleString.Insert(length-3,","): totleString;
For more information , you can refer to
https://learn.microsoft.com/en-us/dotnet/api/system.string.format?view=net-5.0#Starting
Best Regards,
Wenyan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.