首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

delphi7 怎么判断输入的字符串是一个实数(包括指数和小数),请求高手帮忙

2012-12-18 
delphi7 如何判断输入的字符串是一个实数(包括指数和小数),请求高手帮忙内容如题...[最优解释]可以利用类

delphi7 如何判断输入的字符串是一个实数(包括指数和小数),请求高手帮忙
内容如题...
[最优解释]
可以利用类型转换函数,-1代表一个不可能出现的值
Result := StrToFloatDef(XXX, -1) <> -1;
[其他解释]
function   StrToFloat(const   S:   string):   Extended;   
    
Description:     
  Use   StrToFloat   to   convert   astring,   S,   to   a   floating-point   value.   S   must   consist   of   an   optional   sign   (+   or   -),   a   string   of   digits   with   an   optional   decimal   point,   and   an   optional   mantissa.   The   mantissa   consists   of   'E'   or   'e'   followed   by   an   optional   sign   (+   or   -)   and   a   whole   number.   Leading   and   trailing   blanks   are   ignored.      
  The   DecimalSeparator   global   variable   defines   the   character   that   must   be   used   as   a   decimal   point.   Thousand   separators   and   currency   symbols   are   not   allowed   in   the   string.   If   S   doesn't   contain   a   valid   value,   StrToFloat   raises   an   EConvertError   exception.
//if there is a exception, the string isn't a float or double
[其他解释]
typeof()
[其他解释]
顶下,不懂,呵呵!
[其他解释]

引用:
function StrToFloat(const S: string): Extended;  
   
Description:  
  Use StrToFloat to convert astring, S, to a floating-point value. S must consist of an optional sign (+ or -), a string of digi……


麻烦写个实际代码??
[其他解释]
使用正则表达式!可以帮你解决这个问题

[其他解释]
不明白。。
------其他解决方案--------------------


try
  strtofloat(str);
except
  begin
  showmessage('输入数据不是数字');
  exit;
  end;
end;{str 是你想检验的字符串,能成功就成功了,不能成功的话,会提示并退出当前函数块}
注意:把tools->debuger options->integrated debugging 前面的对钩去掉
[其他解释]

引用:
可以利用类型转换函数,-1代表一个不可能出现的值
Result := StrToFloatDef(XXX, -1) <> -1;
可行!

热点排行