擅长:python、mysql、java
<p>使用一个<strong>双</strong>而不是<strong>扩展的</strong>,你会得到相同的结果</p>
<pre><code>procedure TForm1.Button1Click(Sender: TObject);
function map(x, in_min, in_max, out_min, out_max: Integer): Double;
begin
result := (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
end;
var
y, in_min, in_max, out_min, out_max: Integer;
i: Integer;
m: Double;
begin
in_min := 0;
in_max := 6406963;
out_min := 0;
out_max := 474;
y := 0;
for i := in_min to in_max do
begin
m := map(i, in_min, in_max, out_min, out_max);
if round(m) <> y then
begin
y := round(m);
Memo1.Lines.Add(IntToStr(i) + ' = ' + FloatToStr(m));
end;
end;
end;
</code></pre>
<p><strong>编辑:</strong>请参阅大卫的答案以获得解释</p>