当前位置:网站首页>js 语言 精度问题
js 语言 精度问题
2022-06-23 22:20:00 【雷鸣_IT】
例如:
0.1+0.2 !== 0.3
0.1+0.3 === 0.4
0.1+0.4 === 0.5解决精度问题:
1,规定一定范围内 数据的误差允许则等价于相等
export const EPSILON = 0.000001;
/*
* EPSILON(小于等于1.0的值采用绝对公差,大于1.0的值采用相对公差)
* @param a The first number to test.
* @param b The second number to test.
* @return True if the numbers are approximately equal, false otherwise.
*/
export function equals (a: number, b: number) {
return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));
}2,使用字符串进行比对
参考资料:
https://www.iteye.com/blog/thihy-1867577
边栏推荐
- The group procurement management system of daily chemical supplies industry changes the traditional procurement mode and reduces the procurement cost
- Cloud native architecture (05) - Application Architecture Evolution
- Use of reverse tools IDA and GDB
- 并发和并行有什么区别?
- [technical grass planting] Tencent Yunhao wool (consumption) record on the double 11
- 图扑软件智慧风电:数字孪生 3D 风机智能设备运维
- 【面试经验包】面试被吊打经验总结(一)
- 如何利用數倉創建時序錶
- Detailed explanation of index invalidation caused by MySQL
- List<? Extensions T > and list <? Super T > difference
猜你喜欢

物联网卡设备接入EasyCVR,如何查看拉流IP以及拉流时间?

windows10安全模式进入循环蓝屏修复
![[interview experience package] summary of experience of being hanged during interview (I)](/img/ab/ccee8e624248840e712c0b4ca417dd.png)
[interview experience package] summary of experience of being hanged during interview (I)

How to take the PMP Exam agile on June 25? Share your troubles

迷茫的测试/开发程序员,不同人有着不同的故事、有着不同的迷茫......

Cloud native architecture (05) - Application Architecture Evolution

CPU取指到发出控制、微程序控制原理详细过程

Taylor formula and common expansion
![Restore IP address [standard backtracking + standard pruning]](/img/e6/5f9d2a5af973b6c7051ed434a4b93d.png)
Restore IP address [standard backtracking + standard pruning]

跟着CTF-wiki学pwn——ret2text
随机推荐
SQL Server 中 GO 的用法
Solve the problem of project dependency red reporting
String s = new String(“xyz“) 创建了几个字符串对象?
【Bug】C# IQueryable里的元素更改不了值
== 和 equals 的区别是什么?
matlab实现对图像批量重命名
How to use data warehouse to create time series
Recommend 4 flutter heavy open source projects
mcu常用寄存器位操作方式汇总
Visual explanation of clockwise inner curve in Green's formula hole digging method
extern、struct等关键字
Design of message push platform
Taylor formula and common expansion
NLP-D58-nlp比赛D27&刷题D14&读论文&mathtype
【 GBASE的那些事儿】系列直播活动第02期《GBase 8s高可用技术及案例分析法》
暑假第一周
并发和并行有什么区别?
List<? Extensions T > and list <? Super T > difference
APP性能优化之启动流程分析
Notepad++ practical function sharing (common methods for replacing the end and beginning of regular lines, text comparison function, etc.)