下面的代码总是走到
nResult := nResult * 100+ (nTemp div 16) * 10 + (nTemp mod 16);
就编译不过去了、这是为什么呢?
nResult := nResult * 100+ round(nTemp div 16) * 10 + (round(nTemp) mod 16);
下面的代码总是走到
nResult := nResult * 100+ (nTemp div 16) * 10 + (nTemp mod 16);
就编译不过去了、这是为什么呢?
nResult := nResult * 100+ round(nTemp div 16) * 10 + (round(nTemp) mod 16);
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;
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);