开发者

How to format the money using asian format

In India and other Asian countries money is formatted as following: The first three digit开发者_开发技巧s grouped in three then all other digits are grouped in pair of two. eg : 2,54,255.12 5,22,54,255.12 etc string money = String.Format("{0:#,##0.00}", 254255.12);

gives the output 254,255.12

but the output required is 2,54,255.12


Use an appropriate CultureInfo and the "c" format specifier:

CultureInfo hindi = CultureInfo.CreateSpecificCulture("hi-IN");
string text = string.Format(hindi, "{0:c}", 254255.12);

Note that you should really use decimal rather than double for currency values, to avoid binary floating point issues.


This is a straightforward method:

System.Globalization.CultureInfo ci = 
   System.Globalization.CultureInfo.GetCultureInfo("hi-IN");
Console.WriteLine((123456789.87).ToString("N", ci));

Notice that this is accomplished with a correctly configured NumberFormatInfo structure in the format provider / culture object. You can create your own culture objects too, if need be:

foreach (int gs in ci.NumberFormat.CurrencyGroupSizes)
{
   Console.WriteLine(gs);
}

Also note that if the system is configured so that hi-IN is the native culture on the machine, numbers will be formatted that way by default without having to explicitly retrieve the culture and pass it to the format provider argument.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜