C# - When setting a form's opacity should I use a decimal or double?
Translations
Englishالعربية
български
català
中文
čeština
dansk
Nederlands
eesti
suomi
français
Deutsch
Ελληνικά
עברית
हिंदी
magyar
Bahasa Indonesia
italiano
日本語
한국어
latviešu
lietuvių
norsk
polski
Português
română
русский
slovenčina
slovenski
español
svenska
ไทย
Türkçe
українська
Tiếng Việt
I'm new to C#, and 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 try to build it, I get this error:
Cannot implicitly convert type 'decimal' to 'double'
I tried making trans a double, but then the control doesn't work. This code worked fine for me in VB.NET.
What do I need to do differently?
This question and answers originated from www.stackoverflow.com
Question by Eggs McLaren (7/31/2008 9:42:52 PM)
Answer |
An explicit cast to double 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;
Answer by Kevin Dente
Find More Answers