program Project1;{$APPTYPE CONSOLE}uses SysUtils;
function shownum(num:double;precision:integer=4):boolean;
var
messtr:string;
begin
if precision<=-1 then
begin
result:=false;
exit;
end
else
begin
messtr:=format('%*.*',[10,precision,num]);
result:=true;
end;
writeln(messtr);
end;
begin
shownum(123.456789);
shownum(123,5);
shownum(22 div 7,5);
if shownum(123.456789,-3)=false then
writeln('数据格式设置错误,输出失败');
readln;
{ TODO -oUser -cConsole Main : Insert code here }
end.
function shownum(num:double;precision:integer=4):boolean;
var
messtr:string;
begin
if precision<=-1 then
begin
result:=false;
exit;
end
else
begin
messtr:=format('%*.*',[10,precision,num]);
result:=true;
end;
writeln(messtr);
end;
begin
shownum(123.456789);
shownum(123,5);
shownum(22 div 7,5);
if shownum(123.456789,-3)=false then
writeln('数据格式设置错误,输出失败');
readln;
{ TODO -oUser -cConsole Main : Insert code here }
end.
if shownum(123.456789,-3)=false then
shownum()本身就是boolean类型的返回值,应该这样写:if shownum(123.456789,-3) then
if not shownum(123.456789,-3) then
format('%*.*f',[10,precision,num]);
你在'%*.*'后面漏了一个f