输入0 输出0.0
输入1 输出0.1
输入2 输出0.2
输入3 输出0.3
输入4 输出0.4
输入5 输出0.5
输入6 输出0.6
输入7 输出0.7
.
.
.
输入8  输出1.0
输入9  输出1.1
输入10 输出1.2
输入11 输出1.3
输入12 输出1.4
输入13 输出1.5
输入14 输出1.6
输入15 输出1.7
.
.
.
输入16 输出2.0
输入17 输出2.1
输入18 输出2.2
输入19 输出2.3
输入20 输出2.4
输入21 输出2.5
输入22 输出2.6
输入23 输出2.7
.
.
.
依次类推,我输入一个INT型的数据,返回上面形式的数据。
请教这种数据的算法,应该怎么写函数啊!
那位大哥帮看下,救急!

解决方案 »

  1.   

    function int2oct(i:integer):string;
    begin
      result :=inttostr(i div 8) +'.' +inttostr(i mod 8);
    end;
      

  2.   

    反过来,把8进制的转成INT怎么写啊
      

  3.   

    如果也是'x.y'的格式,
    result:=strtoint(s[1])*8+strtoint(s[3]);
      

  4.   

    反推回来不能以1,3位来算,位数应该是不确定的;用pos+copy函数,先求出小数点位置再截取吧s:='256.56';
    i:=pos('.',s);
    result:=strtoint(copy(s,1,i-1))*8+strtoint(copy(s,i+1,length(s)-i));