灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:10420回复:0

检查浮点数精确位数

楼主#
更多 发布于:2012-09-08 13:06

function NumericPrecCheck(compnentCaption,texttring;numericPrec:integer;maxLimit:Integer)tring;
  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;

喜欢0 评分0
游客

返回顶部