当前位置:编程学习 > Delphi >>

检查浮点数精确位数

 
  function NumericPrecCheck(compnentCaption,text:string;numericPrec:integer;maxLimit:Integer):string;
  var
     E: extended;
  begin
    Result:='';
    try
      text:=Trim(text);
      E:=StrToFloat(text);
      if E>maxInt then
      begin
        Result:=compnentCaption+'超过范围'+inttostr(maxLimit)+', 请重新输入!';
      end;
      if ( pos( '.', text ) <> 0 ) and ( length( text ) - pos( '.', text ) >numericPrec )  then
      begin
          Result:=compnentCaption+'只能精确到小数点后' + IntToStr( numericPrec ) + '位,请重新输入!';
      end
      else
      begin
          Result:='格式正确';
      end;
    except
       Result:=compnentCaption+'为数字,请重新输入!';
    end;
  end;
 


摘自 edisonfeng
补充:软件开发 , Delphi ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,