Solved

Problem with implicit conversion of double to float

Posted on 2006-10-21
3
550 Views
Last Modified: 2012-08-13
I have some C# code that is using doubles for coordinate values that are passed to graphics functions such as:

DrawLine (Pen, x1,y1,x2,y2)

where x1, etc are all declared as double, while the methood is defined as

public void DrawLine (
      Pen pen,
      float x1,
      float y1,
      float x2,
      float y2
)



I haven't been able to get this to compile, as I get an error:

Error      2      Argument '1': cannot convert from 'double' to 'float'

I assume this a problem with either the compiler options (to allow the implicit narrowing) or the library (is there are "double" version of System.Drawing.Graphics?
(Using Visual Studio C# 2005 Express compiler)
0
Comment
Question by:JustinFisher
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Raynard7 earned 100 total points
ID: 17782698
Hi,

There is not - however you should be able to use System.Convert.ToSingle()
because with c# float is an alias for single
0
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 17782755
C# is a type safe language, try this

DrawLine (Pen, (float)x1,(float)y1,(float)x2,(float)y2)
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17782764
Or, if that does not work then

DrawLine (Pen, System.Convert.ToSingle(x1),System.Convert.ToSingle(y1),System.Convert.ToSingle(x2),System.Convert.ToSingle(y2));
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now