效果如下, 比较麻烦的方法, 有没有更简单直接的方法? static void Main(string[] args)
{
Byte[] buff = new byte[8];
MemoryStream ms = new MemoryStream(buff);
BinaryReader br = new BinaryReader(ms);
BinaryWriter bw = new BinaryWriter(ms);
long l;
double d;
d = 1235.3424;
bw.Write(d);
ms.Seek(0, SeekOrigin.Begin);
l = br.ReadInt64();
Console.WriteLine("(double){0} binary convert to long is (long){1}", d,l);
Console.Read();
}输出
(double)1235.3424 binary convert to long is (long)4653147908778690714
{
Byte[] buff = new byte[8];
MemoryStream ms = new MemoryStream(buff);
BinaryReader br = new BinaryReader(ms);
BinaryWriter bw = new BinaryWriter(ms);
long l;
double d;
d = 1235.3424;
bw.Write(d);
ms.Seek(0, SeekOrigin.Begin);
l = br.ReadInt64();
Console.WriteLine("(double){0} binary convert to long is (long){1}", d,l);
Console.Read();
}输出
(double)1235.3424 binary convert to long is (long)4653147908778690714
double d = 1235.3424;
long c = BitConverter.ToInt64(BitConverter.GetBytes(d), 0);
double d = 1235.3424;
long c = *(long*)&d;
double d = 1235.3424;
long c = Marshal.ReadInt64(d, 0);