js比较数字相等
示例代碼:
<!DOCTYPE html> <html lang="zh"><head><meta charset="UTF-8" /><title>js比較數字相等</title></head><body><script type="text/javascript">//設置誤差范圍值--機器精度(對于js來說是2^-52)//ES6定義了Number.EPSILON,之前未定義Number.EPSILONif(!Number.EPSILON) {Number.EPSILON = Math.pow(2, -52)}function numberCloseEnoughToEqual(a, b) {return(a - b) < Number.EPSILON;}console.log(numberCloseEnoughToEqual((0.1 + 0.2), 0.3)); //true</script></body></html>?
轉載于:https://www.cnblogs.com/mengfangui/p/8297187.html
總結
- 上一篇: 联想电脑oem系统(联想正版原厂OEM系
- 下一篇: 第二天:Swift手势操控弹性按钮