Gali
Gali

Reputation: 14973

formated numbers on DataGridView not as I need

I have in my C# WinForm DataGridView that holds numbers

the problem is that:

0.5  -->  shows -->  .5     and

-45 -->  shows -->  45-

in my DataGridView the RightToLeft = yes (i must have this)

how I can fix it ?

Upvotes: 3

Views: 413

Answers (3)

Steve
Steve

Reputation: 216353

Use the Format property of a DataGridViewCellStyle.
For example (supposing your first colum's name is "Value")

dataGridView1.Columns["Value"].DefaultCellStyle.Format = "0.0";

The Format property takes strings 'formats' well explained in these articles on MSDN

Custom Numeric Format Strings
Standard Numeric Format Strings

Upvotes: 2

Patrick Guimalan
Patrick Guimalan

Reputation: 1010

double value = .5;
var display = value.ToString("0.00", System.Globalization.CultureInfo.InvariantCulture));

Upvotes: 0

Angshuman Agarwal
Angshuman Agarwal

Reputation: 4866

See the formatting Types & custom numeric format strings here & here

& How to format data in DataGridView here - http://msdn.microsoft.com/en-us/library/f9x2790s.aspx

Upvotes: 0

Related Questions