473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Decimal - Double?

I'm new to C#, and I want to use a trackbar for the forms 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. Any suggestions

Nov 16 '05 #1
3 19540
Bill English <an*******@discussions.microsoft.com> wrote:
I'm new to C#, and I want to use a trackbar for the forms 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.
What do you mean by "doesn't work"? In what way doesn't it work?

You can always cast from decimal to double - in other words explicitly
converting rather than trying to implicitly convert.
This code worked fine for me in VB.NET. Any suggestions?


Did you have option strict on in VB.NET? If not, I suggest you have it
on in future, to give you more type safety. If so, I'm surprised it
worked. (Then again, I'm no VB.NET expert. Maybe it's happy to do
potentially dodgy conversions for you implicitly.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Nevermind, I figured it out, thanks.
Nov 16 '05 #3
How did you make it a double?

first thing I'd try is:

double trans = (double)trackBar1.Value / 5000.0;
this.Opacity = trans;

Math in C# (or maybe all c's) is kind weird....if you devide by an int you get
back an int.

Let me know if there are still problems.

On 27/04/2004 Bill English <an*******@discussions.microsoft.com> wrote:
I'm new to C#, and I want to use a trackbar for the forms 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. Any suggestions?

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
4
by: Ron | last post by:
Greetings, int i = 1, j = 6; double k = (double)i/j; Console.WriteLine(k.ToString()); Console.WriteLine(string.Format(k.ToString(), "0.00")); both yield 0.166666666666667 how can I make...
10
by: Paul Sullivan | last post by:
decimal d; d = 1.1M OR d= (decimal) 1.1 Discussioon
4
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi everyone! I'm using greece - greek in my control panel's regional options, and so, my decimal point is the comma (,), while it is the dot (.) for the sql server db, however, I'm facing...
12
by: ThunderMusic | last post by:
Hi, We have a part of our application that deals with millions of records and do some processing of them. We've achieved a pretty good performance gain by developping a custom DateTime.ToString...
13
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, Why does Math.Sqrt() only accept a double as a parameter? I would think it would be just as happy with a decimal (or int, or float, or ....). I can easily convert back and forth, but I am...
4
by: Todd | last post by:
I have a function that takes a double and truncates it to a specified number of decimal places. I've found that I have to add a small number to the input value otherwise I get errors due to the...
10
by: Jason | last post by:
I'm making a program that will convert decimal inputs (in this case, in inches) and output a fractional answer. At the moment, I'm only able to output the fractional answer in three parts: A whole...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.