Display a number with thousand separator in Indian style using NPOI

后端 未结 3 1344
野趣味
野趣味 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
    

提交回复
热议问题