[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Problem with implicit conversion of double to float

Posted on 2006-10-21
3
Medium Priority
?
557 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 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

834 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