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 对象的字符串;
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, 禁止转载 ️,侵权必究⚠️!