JavaScript中的2 ** 256个BigInteger [英] 2 ** 256 BigInteger in javascript

查看:106
本文介绍了JavaScript中的2 ** 256个BigInteger的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常会得到1.157920892373162e + 77,但是我想要的是2 ** 256的准确数字,例如1157920892731685487456125 .....

Which will normally result in 1.157920892373162e+77 ,but what I want is the accurate number of 2 ** 256 like 1157920892731685487456125.....

我尝试使用big-integer和math.js,但计算后都无法显示所有数字.

I has try big-integer and math.js but both can't show all of the number after calculate.

推荐答案

使用big-integer可以正常工作:

const bigInt = require('big-integer');
let value    = bigInt(2).pow(256);

console.log(value.toString());
// 115792089237316195423570985008687907853269984665640564039457584007913129639936

这篇关于JavaScript中的2 ** 256个BigInteger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆