浮点数比另一个浮点大多少点

  • 本文关键字:多少 另一个 浮点数 javascript
  • 更新时间 :
  • 英文 :


我有一个函数,它接受一个随机浮点数作为参数。函数中的if条件检查浮点数是否等于或大于特定点数,例如0.002另一个恒定的浮点数x。下面是我创建的函数。

function checkRandom({ value }) {
const x = 0.98334
const diff = value - x
if (value == x || (value > x) diff) {
console.log("Match Successful")
} else {
console.log("")
}
}
checkRandom(0.97)

也许你是这个意思?

通过{value}

function checkRandom({value}) {
const x = 0.98334
const diff = value - x;
console.log(diff)
if (value == x || Math.abs(diff) < .002) {
console.log("Match Successful")
} else {
console.log("Difference is greater than .002")
}
}
checkRandom({value:0.98332})

只是通过一个数字

function checkRandom(num) {
const x = 0.98334
const diff = num - x;
console.log(diff)
if (num == x || Math.abs(diff) < .002) {
console.log("Match Successful")
} else {
console.log("Difference is greater than .002")
}
}
checkRandom(0.98332);

相关内容

  • 没有找到相关文章

最新更新