Get the App
SLTechnology News&Howtos  ›  Development  › 

How to take the absolute value of javascript number

Shulou Source: shulou.com Published: 2022-06-02 01:43:06 09月26日 Update

It is believed that many inexperienced people do not know what to do about how to take the absolute value of javascript numbers. therefore, this paper summarizes the causes and solutions of the problem. I hope you can solve this problem through this article.

Javascript numbers take absolute value methods: 1, the use of Math object abs () method, syntax "Math.abs (number)"; 2, the use of "-" operator, syntax "- number"; 3, the use of "*" operator and sqrt () method, syntax "Math.sqrt (a)".

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

Javascript numbers take absolute values

Method 1: use Math.abs ()

Var aaa=-20;console.log (Math.abs (aaa))

Method 2: use the "-" operator

Var aaa=-20;console.log (- aaa)

Note: when using the "-" operator to take an absolute value, you must make sure that the number is negative.

Method 3: using the "*" operator and the sqrt () method

First use the "*" operator to find the square value, and then use the sqrt () method to take the square root

Var Abercrombie Math. Sqrt (a); console.log (a)

What is JavaScript? JavaScript is a literal scripting language whose interpreter is called JavaScript engine and is a part of the browser. JavaScript is a scripting language widely used on the client side. It was first used on HTML pages to add dynamic functions to HTML pages.

After reading the above, have you mastered the method of how to take the absolute value of javascript numbers? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Methods numbers operators operations absolute values syntax content more web pages scripts languages problems helpless for this function dynamic cause customer this object Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Microsoft macOS OPPO Reno Docker