Node JavaScript - 将十进制字符串转换为整数

3
我正在使用一个返回值的Node.js模块,我需要将其转换为字符串或64位整数。 返回的值看起来像这样:{ low: 214107458, high: 17825793, unsigned: true } 文档说明它是一种叫做十进制字符串的东西。我不确定这是什么意思。 我想要的值应该长这样:76561198174373186 我该如何转换呢? 这是我从中获取值的模块: https://github.com/seishun/node-steam 具体来说,是这段代码: https://github.com/seishun/node-steam/blob/84cc4f870b8da4755ba057acff336a093891458f/lib/handlers/friends/index.js 这是我需要发送转换值的模块:https://github.com/Lwatt/node-steam-userinfo/blob/master/index.js 我的代码:
steamFriends.on('friendMsg', function(steamID, message, type) {
    if(type != Steam.EChatEntryType.ChatMsg) return;
    steamuserinfo.getUserInfo(steamID, function(error, data){
        if(error) throw error;
        var datadec = JSON.parse(JSON.stringify(data.response)); //This returns an empty array because steamID is in incorrect form.
        console.log(steamID); //Output: { low: 214107458, high: 17825793, unsigned: true }
    });
});

2
JavaScript没有64位整数。有一些库可以帮助解决这个问题,例如https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/js-ctypes_reference/UInt64。 - John Hascall
十进制意味着基于10的数字,而字符串仍然是字符串。这可能是缺乏64位整数支持的一个黑客/解决方法,正如John已经提到的那样。 - online Thomas
我明白了。然而字符串也可以。有没有一种方法将其转换为一个看起来像这样的字符串“76561198174373186”,还是应该使用那个库? - user3757605
完成了一些格式化。但请包括文档链接、文档引用和您正在使用的模块名称。 - gurvinder372
我已经添加了模块和代码片段。 - user3757605
1个回答

2

我不确定那是什么意思

它的工作原理如下: 76561198174373186 = 17825793 * 10^32 + 214107458

转换为“76561198174373186”字符串的注意事项,最简单的方法是使用支持64位整数的库,自己找吧。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接