2016-01-04 40 views
3

我使用的是Node.js module,它返回一個值,我需要將其轉換爲字符串或64-bit integer。 返回的值是這樣的:節點JavaScript - 十進制字符串爲整數

{ low: 214107458, high: 17825793, unsigned: true }

的文檔指出,這是一種叫做decimal string。我不確定這意味着什麼。 我想要的值是這樣的: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 –

+0

十進制表示10based編號,字符串仍然是字符串。這可能是缺乏64位整數支持的黑客/解決方法,正如John已經提到的那樣。 –

+0

我明白了。然而字符串也很好。有沒有辦法將其轉換爲一個看起來像這樣的字符串「76561198174373186」,還是應該使用該庫? – user3757605

回答

2

我不知道這意味着什麼

它的工作原理是這樣的: 76561198174373186 = 17825793×10^32 + 214107458

NB轉換爲「76561198174373186」的字符串,最簡單的方法是使用支持lib,GIYF的64位整數

相關問題