当前位置:网站首页>为什么 0.1 + 0.2 不等于0.3?如何解决这个问题?
为什么 0.1 + 0.2 不等于0.3?如何解决这个问题?
2022-07-28 20:15:00 【大鸡腿最好吃】
计算机在内部计算实现是把他转化为二进制数相加后再转化为10进制数,js使用双精度浮点数来存储(使用64位固定长度来保存)
0.1和0.2转化为2进制后面是无线循环的1100(两个数均为无限循环小数),所以两者相加自然不等于0.3转化为2进制的值
解决方法
1,将其先转换成整数,再相加之后转回小数
2,使用number对象的toFixed方法,toFixed方法可以指定运算结果的小数点后的指定位数的数字,使保留一位小数就是toFixed(1)
边栏推荐
- Gateway technology of IOT technology stack
- Matlab from introduction to mastery Chapter 1 Introduction to matlab
- I have been in the industry for 4 years and changed jobs twice. I have understood the field of software testing~
- fluke dtx-1800测试精度有必要进行原厂校准吗?
- How does MySQL archive data?
- For the next generation chromebook, MediaTek launched new chipsets mt8192 and mt8195
- Oracle triggers
- Chinese patent keyword extraction based on LSTM and logistic regression
- Divide and conquer, upload large files in pieces
- MATLAB从入门到精通 第1章 MATLAB入门
猜你喜欢

Week 6 Linear Models for Classification (Part B)

Storage and steps of phospholipid coupled antibody / protein Kit

字节一面:TCP 和 UDP 可以使用同一个端口吗?

90. Subset II

磷脂偶联抗体/蛋白试剂盒的存储与步骤

基于复杂网络的大群体应急决策专家意见与信任信息融合方法及应用

大学荒废三年,大四自学7个月测试,找到了12K的工作

KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书

Kubevera plug-in addons download address

fluke dtx-1800测试精度有必要进行原厂校准吗?
随机推荐
LeetCode·581.最短无序连续子数组·双指针
Standard C language learning summary 10
Leetcode 142. circular linked list II [knowledge points: speed pointer, hash table]
Save 70% of the video memory and increase the training speed by 2 times! Zheda & Ali proposed online convolution re parameterization orepa, and the code has been open source! (CVPR 2022 )
Apple M1 processor details: performance and energy efficiency have doubled, and Intel Core i9 is no match!
Technology selection rust post analysis
Storage and steps of phospholipid coupled antibody / protein Kit
基于Paragraph-BERT-CRF的科技论文摘要语步功能信息识别方法研究
纳米金偶联抗体/蛋白试剂盒(20nm,1mg/100μg/500 μg偶联量)的制备
如何优雅的设计工作流引擎(荣耀典藏版)
网格数据生成函数meshgrid
Byte side: can TCP and UDP use the same port?
[hero planet July training leetcode problem solving daily] dynamic planning on the 28th
JVM 内存布局详解(荣耀典藏版)
[英雄星球七月集训LeetCode解题日报] 第28日 动态规划
Msfvenom makes master and controlled terminals
I have been in the industry for 4 years and changed jobs twice. I have understood the field of software testing~
Nano gold coupled antibody / protein Kit (20nm, 1mg/100 μ g/500 μ G coupling amount) preparation
Mysql的B+树高度计算
RHCSA第一天