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 tried using trans
and double
but then the control doesn't work. This code worked fine in a past VB.NET project.
A more generic answer for the generic question "Decimal vs Double?": Decimal for monetary calculations to preserve the precision, Double for scientific calculations that do not get affected by small differences. Since Double is a type which is native to the CPU (internal representation is stored in base 2), calculations made with Double perform better then Decimal (which is represented in base 10 internally).