导航:
论坛 -> DELPHI技术
斑竹:liumazi,sephil
作者:
2004/1/9 16:47:25
标题:
加入我的收藏
楼主:
请教用C++Builder开发的数据计算程序,在Delphi中不知怎么实现。 如下: C++Builder ===== float ASCIIToFloat(char A1,char A2,char A3, char A4) { union { float f; char a[4]; } res; ZeroMemory(&res,sizeof(res)); res.a[0] = A2; res.a[1] = A1; res.a[2] = A4; res.a[3] = A3; return res.f; } void __fastcall TForm1::Button1Click(TObject *Sender) { Edit2->Text=(temp,"%f",ASCIIToFloat('\x01','\xA6','\xC0','\xF1')); //显示结果是 -7.531 } ====================================================================== 谢谢!
----------------------------------------------
-
作者:
sephil (NAILY Soft)
★☆☆☆☆
-
盒子中级会员
2004/1/9 17:14:37
1楼:
function ASCIIToFloat(A1, A2, A3, A4: Byte): Single; type TRes = record A: array[0..3] of Byte; end; var Res: TRes; begin ZeroMemory(@Res, SizeOf(TRes)); with Res do begin A[0] := A2; A[1] := A1; A[2] := A4; A[3] := A3; end; Result := Single(Res); end; procedure TForm1.Button1Click(Sender: TObject); const Temp: String = 'Result = %.3f'; //如果你想显示6个小数位,把上面的 %.3f 改成 %.6f 就可以了,类推 begin Edit1.Text := Format(Temp, [ASCIIToFloat($01, $A6, $C0, $F1)]); //显示结果是 -7.531 end;
----------------------------------------------
Copyright 2008 ? NAILY Soft
Click here to redirect to my home Click here to redirect to my blog