永发信息网

为什么我的这个Delphi除法编译不过去?

答案:2  悬赏:80  手机版
解决时间 2021-05-03 20:48
  • 提问者网友:斑駁影
  • 2021-05-03 14:47

 下面的代码总是走到

nResult := nResult * 100+ (nTemp div 16) * 10 + (nTemp mod 16);

就编译不过去了、这是为什么呢?

nResult := nResult * 100+ round(nTemp div 16) * 10 + (round(nTemp) mod 16);

最佳答案
  • 五星知识达人网友:不如潦草
  • 2021-05-03 15:58


  var
  pointPos:double;
  i,n,temp:integer;
  S1:string;
  minusFlag:double;
  nResult: double;
  nTemp:double;
  nState:Integer;
begin
   S1:= Pchar(Buffer); //把从串口接收的数据赋值到S1中
   nState:=Ord(S1[2]);//检测接收到的BCD码号标识位


   if(nState and $80)>0 then //重量溢出
    nResult:=1002;


   if (nState and $40) = 0 then //重量不稳定
    nResult:= 10003;
    
   if (nState and $20) = 0 then //负数情况
    minusFlag := 1
   else
    minusFlag := -1;
    
   if (nState and $FF) = 0 then  //非记重模式
    nResult:= 10004;


   pointPos:=nState mod 8;  //小数点位置
  
   nResult:=0;  //循环取数值
   for i := Length(S1) downto 3 do
   begin
    nTemp:=ord(s1[i]);
    nResult := nResult * 100+ round(nTemp) div 16* 10 + (round(nTemp) mod 16);//此为最关键部分,进行转换进制
   end;
  
   for i := 1 to trunc(pointPos)-1 do //根据小数点位置处理数值
   begin
    nResult := nResult / 10;
   end;


    nResult := nResult * minusFlag;//结果加正或者负号
   
    Wi_txt.Text:=(floattostr(nResult));
end;

全部回答
  • 1楼网友:行路难
  • 2021-05-03 17:27

nResult := nResult * 100+ round(nTemp div 16) * 10 + (round(nTemp) mod 16);

若nTemp非整型应该为

nResult := nResult * 100+ round(nTemp)  div 16* 10 + (round(nTemp) mod 16);

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯