【问题标题】:jquery math flip pos to neg and neg to posjquery math 将 pos 翻转为 neg 并将 neg 翻转为 pos
【发布时间】:2016-09-22 17:49:58
【问题描述】:

我需要将数字从负数转换为正数,将正数转换为负数。我已经尝试过以下方法,但它只会将正面转换为负面。如果出现负值,则它保持负值。任何帮助将不胜感激。

        // Dials
        g1.refresh(Math.abs(data[0]) * -1);
        g2.refresh(data[1]);
        g3.refresh(data[2]);

【问题讨论】:

标签: javascript jquery math


【解决方案1】:

Math.abs(data[0]) 总是正数,因此与-1 相乘总是会得到负数结果。

使用

g1.refresh(-data[0])

翻转符号。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-16
    • 2021-07-18
    • 1970-01-01
    • 1970-01-01
    • 2021-09-29
    • 2013-10-14
    • 1970-01-01
    相关资源
    最近更新 更多