Archeg
Archeg

Reputation: 8462

String format question

I'm using infragistic grid, and setting DisplayFormat of each column. DisplayFormat is type of string, and uses it`s value to show value of cellValue.ToString(DisplayFormat), when showing values to user in a grid (as Infra docs saying)

In grid I have doubles, that have many numbers after point, and I don`t know how many. And I need to use thousand seperator. So:

If I have:

<br/>
12345678.12345
<br/>
12345678.12
<br/>
, I want grid to show:
<br/>
1234,5678.12345
<br/>1234,5678.12

If I set DisplayFormat to N5, I get: 1234,5678.12000

How can I do that?

Upvotes: 0

Views: 495

Answers (3)

Sebastian Br&#243;zda
Sebastian Br&#243;zda

Reputation: 879

try this

Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-us");
double x = 1234567.2342342d;
Console.WriteLine(string.Format("{0:0,0.00}", x));

output:

1,234,567.23

Upvotes: 0

Joachim VR
Joachim VR

Reputation: 2340

I suggest using N2. The number is the amount of decimals you wish to see, padding it with zeroes, if necessery.

Upvotes: 0

LukeH
LukeH

Reputation: 269388

It's not really clear to me what you want.

  1. If you want to show exactly 2 decimal places then you could use N2.
  2. If you only want to show up to 2 decimal places (if they contain significant figures) then use #,0.##.
  3. If you want to show all significant decimal places then you could use something like #,0.########. (Ideally you'd have about 340 # characters after the decimal point to handle all possible miniscule double values. It's up to you to determine exactly what you need.)

Upvotes: 3

Related Questions