MCPcopy Create free account
hub / github.com/LiuXin-Developer/easyMath / getMaxDecimalDigits

Function getMaxDecimalDigits

src/index.js:28–43  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26
27// 计算最长小数位数
28const getMaxDecimalDigits = function () {
29 let maxDecimalDigits = 0
30 const numberList = arguments[0]
31 for (let i = 0; i < numberList.length; i++) {
32 // 如果是科学计数法
33 if (String(numberList[i]).indexOf("e") !== -1) {
34 numberList[i] = scientificNotationToString(numberList[i])
35 }
36 try {
37 maxDecimalDigits = Math.max(maxDecimalDigits, String(numberList[i]).split(".")[1].length)
38 } catch (e) {
39 maxDecimalDigits = Math.max(maxDecimalDigits, 0)
40 }
41 }
42 return maxDecimalDigits
43}
44// 科学计数法转字符串
45const scientificNotationToString = function (number) {
46 let numberString = String(number)

Callers 4

divisionFunction · 0.85
multiplicationFunction · 0.85
subtractionFunction · 0.85
additionFunction · 0.85

Calls 1

Tested by

no test coverage detected