加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – Val不能与UInt64一起使用?

发布时间:2020-12-15 09:34:10 所属栏目:大数据 来源:网络整理
导读:只是好奇为什么以下代码无法在字符串表示中转换uint64值? var num: UInt64; s: string; err: Integer;begin s := '18446744073709551615'; // High(UInt64) Val(s,num,err); if err 0 then raise Exception.Create('Failed to convert UInt64 at ' + IntToS
只是好奇为什么以下代码无法在字符串表示中转换uint64值?

var
  num: UInt64;
  s: string;
  err: Integer;

begin
  s := '18446744073709551615';  // High(UInt64)
  Val(s,num,err);
  if err <> 0 then
    raise Exception.Create('Failed to convert UInt64 at ' + IntToStr(err));  // returns 20
end.

德尔福XE2

我在这里错过了什么吗?

解决方法

根据 the documentation,

S is a string-type expression; it must be a sequence of characters that form a signed real number.

我同意文件有点模糊;实际上,形式到底意味着什么,以及签名实数的确切含义(特别是如果num是整数类型)?

不过,我认为要突出的部分已签署.在这种情况下,您需要一个整数,因此S必须是一个形成有符号整数的字符序列.但那么你的最大值是高(Int64)= 9223372036854775807

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读