Always return positive value

前端 未结 7 1437
清酒与你
清酒与你 2020-12-11 14:15

I have a number it could be negative or positive but I simply want to return the positive value.

-4 -> 4
5 -> 5

I know I can do a sim

相关标签:
7条回答
  • 2020-12-11 15:17

    Yet another way with Math.CopySign:

    var negativeNum = -5;
    var positiveNum = Math.CopySign(negativeNum, 1); // 5
    
    0 讨论(0)
提交回复
热议问题