Casting from a double to float -- please help!

  • Thread starter Thread starter almurph
  • Start date Start date
A

almurph

Hi,


I'm casting from double to float in C# (yes, I know I will loose
precision but that is okay) but I am having a problem as follows:


double d = 8.5545888281710365;
float f = (float)d;


problem is though - I'm getting 0.0 for the value of the float!
Anyone with any ideas/suggestions as to why this is occuring? Would
appreciate any comments that you are able to offer in this regard.

Thank you,
Al.
 
I'm casting from double to float in C# (yes, I know I will loose
precision but that is okay) but I am having a problem as follows:

double d = 8.5545888281710365;
float f = (float)d;

problem is though - I'm getting 0.0 for the value of the float!

I wrote, compiled and ran the following code:

using System;
class Test
{
public static void Main()
{
double d = 8.5545888281710365;
float f = (float)d;
Console.WriteLine(f);
}
}

It produces the following output:
8.554589

So it is working as expected. Whichever problem is happening in your code is
occurring somewhere else, and not in the two lines that you posted.
 
Back
Top