当前位置:网站首页>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 正确
边栏推荐
猜你喜欢

C语言自定义数据类型——联合体

在项目中使用flex布局的justify-content:space-around;遇到的问题,(数量为单数)

看完这篇博客之后,含着泪学会了TCP/IP

搭建PX4开发环境

【转载】CMake 语法 - 详解 CMakeLists.txt

【网站小白】Hibernate插入数据成功,不报错,但是数据库中没有值

软件测试风险识别

(3) Construction of a real-time performance monitoring platform (Grafana+Prometheus+Node_explorer+Jmeter)

Django--20 implements Redis support, context, and interaction of context and interface

(1) Construction of a real-time performance monitoring platform (Grafana+Influxdb+Jmeter)
随机推荐
旅游住宿酒店14页
设计三级联动
【CSDN21天学习挑战赛】第一天,配置环境外加实现mnist手写数字识别
C语言版通讯录——动态存储(进阶版)
QT circle函数(图片标注)
[C language advanced] The first in-depth analysis of the storage of integer data in memory (1)
一张图带你解读--如何从零开始学习接口自动化
数组的用法
The most complete installation tutorial of Pytorch (one step)
CSDN 社区内容创作规范
C语言结构体详解 (2) 结构体内存对齐,默认对齐数
Install different versions of MinGW (g++/gcc) and the configuration of the corresponding clion editor under Win
C语言自定义类型——枚举类型讲解
怎么用管理员方式打开压缩包
C语言学习记录--变量基本类型和内存大小
搭建PX4开发环境
flaks framework learning: adding variables to the URL
手推卷积神经网络参数(卷积核)求导
第8章 函数探幽 -1
(1) Docker installs Redis in practice (one master, two slaves, three sentinels)