Solved

Problem with implicit conversion of double to float

Posted on 2006-10-21
3
551 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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 is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 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