Display number with commas and decimal points

I want to show a number with commas and decimal point

CASE1: example if number 3494309432324

displayed as 34.94,30.94,32,324 but not 34,94,30,94,32,324.00

Case 2: if the number has decimal values ​​up to 2 decimal places and with commas

displayed as 12,22,222,32

I am currently doing this for 2 decimal places, but I am not getting commas

Label9.Text = sisRatio.ToString("#0.00");

any suggestions..

thanks

+6
source share
6 answers

Assuming you need the usual 3 digits and then a comma, I think this will do what you need:

 Label9.Text = sisRatio.ToString("#,##0.##"); 

One of the minor issues is that it will only have one decimal place if the second is 0

+11
source share

Try:

 Label9.Text = sisRatio.ToString("##,0.00"); 

I assume that you want to divide the groups into thousands, not hundreds, as your question. Note that this will use a localized delimiter for the current culture.

+4
source share

The following approach should give you what you are looking for:

 double d = 123456789.1; string format = d.ToString().IndexOf(NumberFormatInfo.CurrentInfo.NumberDecimalSeparator) >=0 ? "#,##0.00" : "#,##0"; Console.WriteLine (d.ToString(format)); 

This will also work for cultures that do not have three-digit groups.

+4
source share

There seem to be two ways to answer this question:

  • An algorithmic answer that gives a number in the specified format, i.e. 2 digits between commas.

  • It turned out that this is a relative solution for the locale, since I can not get any of the ToString () suggestions to work on my PC.

This question caught me initially, as it is not as simple as it seems.

+2
source share

This will work:

 Label9.Text = sisRatio.ToString("#,0.00"); //changed from "#0,0.00" to "#,0.00" 
+1
source share

try it

  Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Thread.CurrentThread.CurrentCulture = New CultureInfo("hi-IN") End Sub 

and.....

 Private Sub txtData_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtData.Leave If IsNumeric(txtData.Text) Then Dim xData As Integer = txtData.Text txtData.Text = xData.ToString("##,0.00") End If End Sub 
-one
source share

All Articles