前端知识学习

javascript定义的数据类型里并没有Long类型,需要使用long.js插件模拟
github下载地址:https://github.com/dcodeIO/long.js
npm下载地址:https://www.npmjs.com/package/long

Long与Number、String转换

const Long = require("long");
//语法: new Long(low: number, high: number, unsigned?: boolean)

/* Number转Long */
let num = 1234567890123456;
console.log(Long.fromNumber(num));  //Long {low: 1015724736, high: 287445, unsigned: false}

/* String转Long */
let str = '1234567890123456';
console.log(Long.fromString(str)); //Long {low: 1015724736, high: 287445, unsigned: false}

/* Long转Number*/
let lng = new Long(1015724736, 287445); 
console.log(lng.toNumber()); 

/* Long转String*/
let lng = new Long(1015724736, 287445); 
console.log(lng.toString());