views:

70

answers:

3

Hi, 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?

+3  A: 

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.)
LukeH
I want to show all digits, that number have. But I want to ignore last zeros. So, if I have 1.8900000, I need to show just 1.89
Archeg
Thanks, third choice, even if it is ugly, is working) Really strange, why fw hasn`t a better way to provide such formats - I think they are very user-friendly
Archeg
In that case you'll need option *(3)* above: `#,0.########`, and if you anticipate values smaller than `0.00000001` then you'll need to add more `#` characters after the decimal point (up to 340 of them, which I think is enough to handle any tiny `double` value).
LukeH
A: 

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

Joachim VR
I need all numbers after point, I have values like this: 11234.271653876127836781263187, and 123213.12 It will be difficult to read 123213.1200000000000000 =)
Archeg
A: 

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

Sebastian Brózda