Mandar Jogalekar
Mandar Jogalekar

Reputation: 3281

convert formatted decimal string with thousand seperator

I could not find answer which combines the two here.

I am getting from the database for example 8120.349 and looking to convert this to two decimal and thousand seperator. so ideal output string I am looking for here is 8,120.35

Currently I am converting to two decimal using

MaxValue.ToString("F2") //maxvalue is decimal

this outputs me 8120.35

tried adding this for thousand seperator after looking at few answers.

String.Format("{0:n}", MaxValue.ToString("F2"))

this still gives me same output.

any ideas here?

Upvotes: 2

Views: 123

Answers (3)

ercyon
ercyon

Reputation: 111

Also you can use a hand made formatting,

string.Format("{0:#,##0.00}", 8120.349)

Upvotes: 0

Edward N
Edward N

Reputation: 997

You should use : Standard Numeric("N") Format Specifier

double number = 8120.349;

var stringFormatted = number.ToString("n");

Upvotes: 1

Jcl
Jcl

Reputation: 28272

You could use MaxValue.ToString("N2")

Fiddle: https://dotnetfiddle.net/uEBlPA

Upvotes: 4

Related Questions