Why is Datagridview cell always rounding to int

R

R Reyes

Hi, I'm having a weird problem. This datagridview keeps rounding my cell
values to an integer. Why does it do this and how can I stop it?

I am working with money and even after i set the ValueType of the cell to
typeof(double), it always tries to round to an int anyway.

Here's the code:
double dblNumber = 567.89;
dgv.Columns[4].ValueType = typeof(double);
dgv.Rows.Cells[4].Value = dblNumber;

// this always returns 568 ....why?

Any ideas on why this happens and how I can stop it?

Thanks for your time.
 
D

DH

R said:
Hi, I'm having a weird problem. This datagridview keeps rounding my cell
values to an integer. Why does it do this and how can I stop it?

I am working with money and even after i set the ValueType of the cell to
typeof(double), it always tries to round to an int anyway.

Here's the code:
double dblNumber = 567.89;
dgv.Columns[4].ValueType = typeof(double);
dgv.Rows.Cells[4].Value = dblNumber;

// this always returns 568 ....why?

Any ideas on why this happens and how I can stop it?

Thanks for your time.

The code you have given works for me. I get 567.89.
I copied/pasted your exact code.
There must be something else happening, please provide more detail,what
framework is it a simple datagridview or a custom.
 
R

R Reyes

Figured it out.

In the SQL statement, I was providing a preset value "SELECT 0 AS Number
FROM TBL". Once I casted that to type money it never tried rounded to int
anymore.

So to solve, I used "SELECT CAST(0.00 AS Money) AS Number FROM TBL" instead.

Fixed. Thanks for your time!

DH said:
R said:
Hi, I'm having a weird problem. This datagridview keeps rounding my cell
values to an integer. Why does it do this and how can I stop it?

I am working with money and even after i set the ValueType of the cell to
typeof(double), it always tries to round to an int anyway.

Here's the code:
double dblNumber = 567.89;
dgv.Columns[4].ValueType = typeof(double);
dgv.Rows.Cells[4].Value = dblNumber;

// this always returns 568 ....why?

Any ideas on why this happens and how I can stop it?

Thanks for your time.

The code you have given works for me. I get 567.89.
I copied/pasted your exact code.
There must be something else happening, please provide more detail,what
framework is it a simple datagridview or a custom.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top