开发者

display number with commas and decimal points

I want to display a number with commas and decimal point

CASE1 : example if the number is 3494309432324

display as 34,94,30,94,32,324 but not 34,94,30,94,开发者_运维知识库32,324.00

Case 2 : if the number has decimal values them till 2 decimal points and with commas

display as 12,22,222.32

currently i do this for 2 decimal places but i dont get the commas

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

any suggestions..

thanks


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

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

One slight issue with this is that it will only one decimal place if the second one would be 0


Try:

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

I'm assuming that you want to separate groups by thousands and not by hundreds as in your question. Note that this will use the localized separator for the current culture.


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 does not have 3-digit groups.


It seems that there are two ways to answer this question:

  1. An algorithmic answer which gives the number in the specified format i.e. 2 digits between the commas.

  2. Working out that this is a locale-relative solution, since I can't get any of the given ToString() suggestions to work on my PC.

This question caught me out initially as it's not as easy as it looks.


This will work:

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


Try This

    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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜