Display a number with thousand separator in Indian style using NPOI

后端 未结 3 1262
野趣味
野趣味 2021-01-27 10:42

I am using VS2008,ASP.net,C#.net.

I have a web applicaion which uses NPOI dll to export to excel 2003. How do I display a number with thousand separator in Indian style(

相关标签:
3条回答
  • 2021-01-27 11:00

    Depending on your CultureInfo, it should work with the format string "N".

    Check your CultureInfo.CurrentCulture.NumberFormat.NumberGroupSizes. If it is {3, 2, }, you are happy. So:

    yourNumber.ToString("N")
    

    You can give another culture if your current culture is not good, for example:

    yourNumber.ToString("N", new CultureInfo("hi-IN"))
    

    On my system, (121234567.89).ToString("N", new CultureInfo("hi-IN")) gives "12,12,34,567.89". Those are the group sizes you desire.

    As you may know, formatting can also take place like this:

    string.Format(new CultureInfo("hi-IN"), "The number {0:N} is well formatted", yourNumber)
    

    Addition: Out of curiosity, I just tested which specific cultures on my system use the {3, 2, } number group sizes, and they are:

    hi-IN
    bn-IN
    pa-IN
    gu-IN
    or-IN
    ta-IN
    te-IN
    kn-IN
    ml-IN
    as-IN
    mr-IN
    sa-IN
    kok-IN
    si-LK
    ne-NP
    bn-BD
    en-IN
    
    0 讨论(0)
  • 2021-01-27 11:05

    with NPOI try this magic to format with Indian style:

    ICell cell = row.GetCell(0);
    cell.SetCellValue(1234567.89d);
    IDataFormat dataFormatCustom = workbook.CreateDataFormat();
    cell.CellStyle.DataFormat = dataFormatCustom.GetFormat("[>=10000000]##\\,##\\,##\\,##0;[>=100000] ##\\,##\\,##0;##,##0.00");
    
    0 讨论(0)
  • 2021-01-27 11:10

    Try this

    int value 773740;
    Response.Write(value.ToString("N"));
    //or
    Response.Write(value.ToString("#,#"));
    

    To format double to string with use of thousands separator use zero and comma separator before an usual float formatting pattern, e.g. pattern „0,0.0“ formats the number to use thousands separators and to have one decimal place.

    String.Format("{0:0,0.0}", 12345.67);     // "12,345.7"
    String.Format("{0:0,0}", 12345.67);       // "12,346"
    

    Refer more here http://www.csharp-examples.net/string-format-double/

    0 讨论(0)
提交回复
热议问题