xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

js exponential notation show big number bug

js exponential notation show big number bug

js 科学计数法 bug

big = 1000000000000000000000000000001 + 465;
// 1e+30

big.toFixed(1);
// '1e+30'

big.toLocaleString();
// '1,000,000,000,000,000,000,000,000,000,000'

big.toString();
// '1e+30'

一个用幂的形式 (科学记数法) 来表示 Number 对象的字符串;

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential

BigInt

const bigNum = BigInt(1000000000000000000000000000001 + 465);
// 1000000000000000019884624838656n

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt

demo


const bigNum = 1000000000000000000000000000001 + 465;
// 1e+30

const bigNum = 1000000000000000000000000000001 + 465;

const arr1 = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1];
const arr2 = [5,6,4];
// 数组相加 ?


const arr = [6,6,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1].reverse().join('');

// '1000000000000000000000000000466'

https://leetcode.com/problems/add-two-numbers/

refs



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2022-03-17 22:20  xgqfrms  阅读(33)  评论(2编辑  收藏  举报