数控程序中的数字输出一般遵循以下几个规则:

  1. 精度保留到小数点后三位

         主流数机床的精度都是微米级,即千分之一毫米,故保留三位小数。

  1. 除去前导零和后尾零

         如-0.250可以写成-.25。

  1. 整数也要保留小数点

         比如1要写成1.。这主要是考虑到兼容性。

         有些系统(如Fanuc 31i-Model B)默认单位是微米。G91X1实际相当于G91X.001,G91X1.才是X轴向正方向移动1个毫米。

 

function FormatNum(const x: Real): String;
var
  i: Integer;
  s: String;
begin
  if Abs(x)<5E-4 then begin Result:='0.'; Exit; end;
  Str(x:0:3,s);
  i:= Length(s);
  while s[i]='0' do
    dec(i);
  s:= Copy(s,1,i);
  if s[1] = '0' then s:= Copy(s,2,Length(s)-1);
  if (s[2] = '0') and (x<0) then s:= '-'+Copy(s,3,Length(s)-2);
  Result:= s;
end;

 

posted on 2021-08-30 15:48  一只小边牧  阅读(470)  评论(0编辑  收藏  举报