Converting decimal type to double

  • Thread starter Thread starter .Net Sports
  • Start date Start date
N

.Net Sports

I have an itemdatabound function whereas I am declaring a var named
"price" as a decimal, and then want to reassign it to the value of a
double datatype "dblTotalVolume", but I get an error "cannot implicitly
convert type 'decimal' to 'double' , even tho in similar scripts with
the exact same statements, I don't get an error and my function works:

decimal price;
price = System.Convert.ToDecimal(rowData["dblTotalVolume"]);

??
..Netsports
 
..Net Sports said:
I have an itemdatabound function whereas I am declaring a var named
"price" as a decimal, and then want to reassign it to the value of a
double datatype "dblTotalVolume", but I get an error "cannot implicitly
convert type 'decimal' to 'double' , even tho in similar scripts with
the exact same statements, I don't get an error and my function works:

decimal price;
price = System.Convert.ToDecimal(rowData["dblTotalVolume"]);

??

Because you could be losing information, you need to cast it:

dblTotalVolume = (double) price;

Jon
 
Back
Top