当前位置:网站首页>ES11新增数据类型BigInt大整型
ES11新增数据类型BigInt大整型
2022-08-11 05:17:00 【前端小马】
bigint使用方式:
1.直接添加字母n
var num=100n;
console.log(typeof num)//bigint
2.使用bigint函数
var num=100;
console.log(typeof BigInt(num))//bigint
注意:
1. 小数不能转为bigint类型
var num=100.1;
console.log(BigInt(num))//报错
2. bigint类型只能与bigint类型做运算
var num=100
console.log(BigInt(num)+1)//报错
为了计算的准确性,js定义了最大安全整数,这个整数是
let max=Number.MAX_SAFE_INTEGER
console.log(max)//9007199254740991
在最大安全值得基础上不断+1计算就会出错
let max=Number.MAX_SAFE_INTEGER
console.log(max)//9007199254740991
console.log(max+1)//9007199254740992 正确
console.log(max+2)//9007199254740992 错误
console.log(max+4)//9007199254740996 错误
而用bigInt()方法将数转成大整型就能解决这个问题
let max=Number.MAX_SAFE_INTEGER
console.log(BigInt(max))//9007199254740991n
console.log(BigInt(max)+BigInt(1))//9007199254740992n 正确
console.log(BigInt(max)+BigInt(2))//9007199254740993n 正确
console.log(BigInt(max)+BigInt(4))//9007199254740995n 正确
边栏推荐
猜你喜欢
06-引入Express创建web服务器、接口封装并使用postman测试,静态资源托管
【CSDN21天学习挑战赛】第一天,配置环境外加实现mnist手写数字识别
Flask framework learning: template inheritance
(1) Docker installs Redis in practice (one master, two slaves, three sentinels)
C语言动态内存分配(1)三种函数讲解
【win10+cuda7.5+cudnn6.0安装caffe③】编译及测试caffe
C语言自定义数据类型——联合体
简单做份西红柿炒蛋778
在项目中使用flex布局的justify-content:space-around;遇到的问题,(数量为单数)
吃瓜教程task04 第5章 神经网络
随机推荐
Some Error in Visual Studio solution
04-开发自己的npm包及发布流程详细讲解
c pointer learning (2)
C语言结构体详解 (2) 结构体内存对齐,默认对齐数
【win10+cuda7.5+cudnn6.0安装caffe⑥】报错及处理方式
第5章 循环和关系表达式
函数怎么用
Minecraft
QT QLabel控件(使用详解)
LeetCode1166. Designing File Systems
Redis - Data Types (Basic Instructions, String, List, Set, Hash, ZSet, BitMaps, HyperLogLog, GeoSpatial) / Publish and Subscribe
C语言自定义类型——枚举类型讲解
【无标题】
【C语言进阶】第一篇深度剖析整数数据在内存中的存储(一)
EOF, feof function, ferror function in C language
C语言之EOF、feof函数、ferror函数
npm install 时报 npm ERR Cannot read properties of null (reading ‘pickAlgorithm‘)
做款好喝的茶饮~
第13章 类的继承-1
CSDN 社区内容创作规范