Athul Athul - 3 months ago 11
ASP.NET (C#) Question

String.Format an integer to use a thousands separator with decimal value in danish culture

I have a string

totalPRice
which holds a value like this
1147,5

I want two things.

1)round the value so that there is always two digits after
,


2)Implement thousands separator in this string, So that final out put will be some thing like this
1.147,50


I have tried some thing like this

String.Format("{0:0.00}", totalPRice)


It does my first requirement correctly by producing an output
1147,50
.
But I am way behind in my second requirement. Can any one tell me how I can achieve this?

Note: In danish culture
.
stands for
,
and
,
stands for
.

Answer

You can refer to Standard Numeric Format Strings and use

string.Format("{0:N2}", 1234.56)

You may also specify the culture manually, if danish is not your default culture:

var danishCulture = CultureInfo.CreateSpecificCulture("da-DK");
string.Format(danishCulture, "{0:N2}", 1234.56);

see MSDN Reference for CultureInfo

Comments