当前位置:网站首页>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 正确
边栏推荐
- 【win10+cuda7.5+cudnn6.0安装caffe③】编译及测试caffe
- C语言——动态内存分配常见的错误案例
- 吃瓜教程task05 第6章 支持向量机
- 在项目中使用flex布局的justify-content:space-around;遇到的问题,(数量为单数)
- C语言——函数的使用
- 【C语言从初阶到进阶】第二篇 初始C语言(二)
- 【备忘】从零开始搭建Yolo5训练环境
- (2) Docker installs Redis in practice (persistent AOF and RDB snapshots)
- 08-Express路由详解
- Flask framework learning: template rendering and Get, Post requests
猜你喜欢
随机推荐
Django--20 implements Redis support, context, and interaction of context and interface
【C语言从初阶到进阶】第一篇 初始C语言(一)
C language learning record--variable basic type and memory size
Chapter 4 Composite Types-1
(3) Construction of a real-time performance monitoring platform (Grafana+Prometheus+Node_explorer+Jmeter)
【网站小白】Hibernate插入数据成功,不报错,但是数据库中没有值
【C语言从初阶到进阶】第二篇 初始C语言(二)
Flask framework to study: the debug and configuration items
(3) How Redis performs stress testing
【win10+cuda7.5+cudnn6.0安装caffe③】编译及测试caffe
win下Anaconda(环境配置等)和pycharm安装详细教程
The most complete installation tutorial of Pytorch (one step)
Flask框架学习:路由的尾部斜杠
更新啦~人生重开模拟器自制
第8章 函数探幽 -1
Solidrun hummingboard制作SD卡
LeetCode1166. Designing File Systems
吃瓜教程task02 第3章 线性模型
Chapter 5 Loops and Relational Expressions
CSDN 社区内容创作规范









