question

Borisoprit-6789 avatar image
0 Votes"
Borisoprit-6789 asked Borisoprit-6789 answered

Change format of outcome of Sum


 I make a simple calculation with some Entry's , that works but this is not the format i really am looking for.


Totaaltanks.Text = total.ToString("N0", CultureInfo.InvariantCulture);

The outcome is for example 10,245,458
The format that i am looking for is that the outcome is 10245,458
With 1 comma only .

Tryed al lot of options but cannot find the one i am looking for.












dotnet-xamarinforms
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

May I know if you have got any chance to check my answer? I am glad to help if you have any other questions.

0 Votes 0 ·
WenyanZhang-MSFT avatar image
0 Votes"
WenyanZhang-MSFT answered

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://docs.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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Borisoprit-6789 avatar image
0 Votes"
Borisoprit-6789 answered

Thanks Wenyan Zhang ,

I used this

 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;
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.