-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlogEtoDecimal.JS
More file actions
96 lines (72 loc) · 2.75 KB
/
Copy pathlogEtoDecimal.JS
File metadata and controls
96 lines (72 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//Added by Yogesh - 01/11/19 - To convert logarithm value like 1e23 into 10000000.. Start----->
function logEtoDecimal(amountInLogE, decimal){
amountInLogE = amountInLogE.toString();
var noDecimalDigits = "";
if(amountInLogE.includes("e-")){
var splitString = amountInLogE.split("e-"); //split the string from 'e-'
noDecimalDigits = splitString[0].replace(".", ""); //remove decimal point
var zerosToAdd = splitString[1] - noDecimalDigits.length;
for(var i=0; i < zerosToAdd; i++){
noDecimalDigits += "0";
}
if(splitString[1] < decimal){
return noDecimalDigits;
}
else{
return 0;
}
}
else if(amountInLogE.includes("e+")){
var splitString = amountInLogE.split("e+"); //split the string from 'e+'
noDecimalDigits = splitString[0].replace(".", ""); //remove decimal point
var zerosToAdd = splitString[1] - noDecimalDigits.length;
for(var i=0; i <= zerosToAdd; i++){
noDecimalDigits += "0";
}
return noDecimalDigits;
}
else if(amountInLogE.includes(".")){
var splitString = amountInLogE.split("."); //split the string from '.'
return splitString[0];
}
return amountInLogE;
}
//following function returns original value of logarithm value like 1e24
function logEtoLongNumber(amountInLogE){
amountInLogE = amountInLogE.toString();
var noDecimalDigits = "";
if(amountInLogE.includes("e-")){
var splitString = amountInLogE.split("e-"); //split the string from 'e-'
noDecimalDigits = splitString[0].replace(".", ""); //remove decimal point
//how far decimals to move
var zeroString = "";
for(var i=1; i < splitString[1]; i++){
zeroString += "0";
}
return "0."+zeroString+noDecimalDigits;
}
else if(amountInLogE.includes("e+")){
var splitString = amountInLogE.split("e+"); //split the string from 'e+'
var ePower = parseInt(splitString[1]);
noDecimalDigits = splitString[0].replace(".", ""); //remove decimal point
if(ePower >= noDecimalDigits.length-1){
var zerosToAdd = ePower - noDecimalDigits.length;
for(var i=0; i <= zerosToAdd; i++){
noDecimalDigits += "0";
}
}
else{
//this condition will run if the e+n is less than numbers
var stringFirstHalf = noDecimalDigits.slice(0, ePower+1);
var stringSecondHalf = noDecimalDigits.slice(ePower+1);
return stringFirstHalf+"."+stringSecondHalf;
}
return noDecimalDigits;
}
else if(amountInLogE.includes(".")){
var splitString = amountInLogE.split("."); //split the string from '.'
return splitString[0];
}
return amountInLogE; //by default it returns stringify value of original number if its not logarithm number
}
//Added by Yogesh - 01/11/19 - To convert logarithm value like 1e23 into 10000000.. END ----->