当前位置:网站首页>为什么 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)
边栏推荐
- Official document of kubevela 1.4.x
- The general strike of three factories in St France may make the shortage of chips more serious!
- 中国农业工程学会农业水土工程专业委员会-第十二届-笔记
- ESP8266-Arduino编程实例-定时器与中断
- Knowledge description framework of foreign patent documents based on knowledge elements
- Oracle, SQL Foundation
- 比UUID更快更安全NanoID到底是怎么实现的?(荣耀典藏版)
- Week 6 Linear Models for Classification (Part B)
- Esp8266 Arduino programming example - deep sleep and wake up
- Leetcode · 581. shortest unordered continuous subarray · double pointer
猜你喜欢

The University was abandoned for three years, the senior taught himself for seven months, and found a 12K job

LeetCode·581.最短无序连续子数组·双指针

Versailles ceiling: "the monthly salary of two years after graduation is only 35K, which is really unpromising ~ ~"

Research on the recognition method of move function information of scientific paper abstract based on paragraph Bert CRF

凡尔赛天花板:“毕业两年月薪才35K,真是没出息啊~~”

Cross domain transfer learning of professional skill word extraction in Chinese recruitment documents

小程序开发需要什么技术

Research on intangible cultural heritage image classification based on multimodal fusion

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

Open earphone which air conduction earphone with good sound quality and recognized sound quality is recommended
随机推荐
With the help of domestic chip manufacturers, the shipment of white brand TWS headphones has reached 600million in 2020
ESP8266-Arduino编程实例-SPIFFS及数据上传(Arduino IDE和PlatformIO IDE)
如何优雅的设计工作流引擎(荣耀典藏版)
RHCSA第一天
使用Mock技术帮助提升测试效率的小tips,你知道几个?
Byte side: can TCP and UDP use the same port?
[极客大挑战 2019]Secret File&文件包含常用伪协议以及姿势
Implementation of sequence table
39. 组合总和
Zhuzhou Jiufang middle school carried out drowning prevention and fire safety education and training activities
90. Subset II
中文招聘文档中专业技能词抽取的跨域迁移学习
Object based real-time spatial audio rendering - Dev for dev column
For the next generation chromebook, MediaTek launched new chipsets mt8192 and mt8195
How does MySQL archive data?
II. Explanation of the sequence and deserialization mechanism of redistemplate
两个全局变量__dirname和__filename 、fs模块常用功能进一步介绍
Mysql的B+树高度计算
系统分析师
入行4年,跳槽2次,我摸透了软件测试这一行~