?
Solved

Problem with implicit conversion of double to float

Posted on 2006-10-21
3
Medium Priority
?
556 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Raynard7 earned 300 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

650 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