How does JavaScript calculate digital subtraction
This article mainly introduces how JavaScript calculates digital subtraction, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let's take a look at it.
NumSub-Computational digit subtraction
Function numSub (num1, num2) {let baseNum, baseNum1, baseNum2; let precision;// precision try {baseNum1 = num1.toString (). Split (".") [1] .length;} catch (e) {baseNum1 = 0;} try {baseNum2 = num2.toString (). Split (".") [1] .length;} catch (e) {baseNum2 = 0 } baseNum = Math.pow (10, Math.max (baseNum1, baseNum2)); precision = (baseNum1 > = baseNum2)? BaseNum1: baseNum2; return ((num1 * baseNum-num2 * baseNum) / baseNum) .tofixed (precision);}; what are the characteristics of JavaScript: 1. Js belongs to an interpretive scripting language; 2. With the support of most browsers, js can run on multiple platforms and has cross-platform features. 3. Js belongs to a weak type scripting language, which does not make strict requirements for the data types used, and can convert types, which is simple and easy to use; 4. Js language has high security, and it can only browse information or interact dynamically through the browser, thus effectively preventing the loss of data; 5, object-based scripting language, js can not only create objects, but also use existing objects.
Thank you for reading this article carefully. I hope the article "how to calculate the subtraction of JavaScript" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!