Search  


Helper: Convert Decimal to a Double 
Tuesday, April 21, 2020, 10:23 PM
Posted by Administrator
Q: I want to use a Track-Bar to change a Form's opacity.

This is my code:

decimal trans = trackBar1.Value / 5000;
this.Opacity = trans;
When I build the application, it gives the following error:

Cannot implicitly convert type decimal to double
I have tried using trans and double but then the Control doesn't work. This code worked fine in a past VB.NET project.

A: An explicit cast to double like this isn't necessary:

double trans = (double) trackBar1.Value / 5000.0;
Identifying the constant as 5000.0 (or as 5000d) is sufficient:

double trans = trackBar1.Value / 5000.0;
double trans = trackBar1.Value / 5000d;


add comment ( 97 views )   |  permalink   |  $star_image$star_image$star_image$star_image$star_image ( 3 / 442 )

<<First <Back | 1119 | 1120 | 1121 | 1122 | 1123 | 1124 | 1125 | 1126 | 1127 | 1128 | Next> Last>>







Share CertificationPoint & Stay Informed Socially About EduTech?