Get the absolute value of a number in Javascript

后端 未结 5 955
盖世英雄少女心
盖世英雄少女心 2020-12-13 08:34

I want to get the absolute value of a number in JavaScript. That is, drop the sign. I know mathematically I can do this by squaring the number then taking the square root, b

5条回答
  •  醉梦人生
    2020-12-13 09:01

    I think you are looking for Math.abs(x)

    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Math/abs

提交回复
热议问题