如何在 Actionscript 3 中检查一个数字是否位于另外两个数字之间?

发布于 2024-12-11 04:49:02 字数 259 浏览 6 评论 0原文

我如何检查一个数字是否在两个其他数字之间,例如:

伪代码:

var = 458;

if (var is between 0 and 1000) give positive.

if (var is between 1001 and 2000) give negative.

if (var is between 2001 and 3000) give negative.

在 AS3 中?

提前致谢。

How can i check if a number is between two other numbers like:

pseudocode:

var = 458;

if (var is between 0 and 1000) give positive.

if (var is between 1001 and 2000) give negative.

if (var is between 2001 and 3000) give negative.

in AS3?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我很OK 2024-12-18 04:49:02

如果您要多次检查,只需创建函数:

function check(min:Number , value:Number , max:Number):Boolean{
    return min > value ? false : ( max < value ? false : true );
}

如果值在最小值和最大值之间,它将返回 true。

If You will check it many times, simply create function :

function check(min:Number , value:Number , max:Number):Boolean{
    return min > value ? false : ( max < value ? false : true );
}

It will return true if value is between min and max.

伊面 2024-12-18 04:49:02
if (var >= 0 && var <= 1000) {
  return true
}
else if (var >= 1001 && var <= 2000) {
  return false
}
else if (var >= 2001 && var <= 3000) {
  return false
}

但条件 2 和 3 都返回 false,并且条件也计算为 true/false,因此您可以简单地:

return (var >= 0 && var <= 1000)
if (var >= 0 && var <= 1000) {
  return true
}
else if (var >= 1001 && var <= 2000) {
  return false
}
else if (var >= 2001 && var <= 3000) {
  return false
}

But conditions 2 and 3 both return false, and the condition also evaluate to true/false, so you could simply:

return (var >= 0 && var <= 1000)
把时间冻结 2024-12-18 04:49:02

框架中有一个方法专门用于此目的:

mx.utils.ObjectUtil::numericComapre()

来自文档:

比较两个数值。返回 int — 0 表示两个数字均为 NaN。如果只有 a 是 NaN,则为 1。如果只有 b 是 NaN,则为 -1。如果 a 小于 b,则为 -1。如果 a 大于 b,则为 1。

There's a method in the framework just for that:

mx.utils.ObjectUtil::numericComapre()

From the docs:

Compares two numeric values. Returns int — 0 is both numbers are NaN. 1 if only a is a NaN. -1 if only b is a NaN. -1 if a is less than b. 1 if a is greater than b.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文